Update AdminController

This commit is contained in:
Daniel Supernault 2018-12-20 23:14:22 -07:00
parent 53fa1326d4
commit 51c3be37d3
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -3,19 +3,23 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Media; use App\Media;
use App\Like;
use App\Profile; use App\Profile;
use App\Report; use App\Report;
use App\Status; use App\Status;
use App\User; use App\User;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Jackiedo\DotenvEditor\DotenvEditor;
use App\Http\Controllers\Admin\{ use App\Http\Controllers\Admin\{
AdminReportController AdminReportController,
AdminSettingsController
}; };
use App\Util\Lexer\PrettyNumber;
class AdminController extends Controller class AdminController extends Controller
{ {
use AdminReportController; use AdminReportController, AdminSettingsController;
public function __construct() public function __construct()
{ {
@ -30,15 +34,16 @@ class AdminController extends Controller
public function users(Request $request) public function users(Request $request)
{ {
$stats = []; $col = $request->query('col') ?? 'id';
$users = User::orderBy('id', 'desc')->paginate(10); $dir = $request->query('dir') ?? 'desc';
$stats = $this->collectUserStats($request);
$users = User::withCount('statuses')->orderBy($col, $dir)->paginate(10);
return view('admin.users.home', compact('users', 'stats')); return view('admin.users.home', compact('users', 'stats'));
} }
public function editUser(Request $request, $id) public function editUser(Request $request, $id)
{ {
$user = User::find($id); $user = User::findOrFail($id);
$profile = $user->profile; $profile = $user->profile;
return view('admin.users.edit', compact('user', 'profile')); return view('admin.users.edit', compact('user', 'profile'));
} }
@ -98,7 +103,7 @@ class AdminController extends Controller
'remote' => Profile::whereNotNull('remote_url')->count() 'remote' => Profile::whereNotNull('remote_url')->count()
]; ];
$stats['avg'] = [ $stats['avg'] = [
'age' => 0, 'likes' => floor(Like::average('profile_id')),
'posts' => floor(Status::avg('profile_id')) 'posts' => floor(Status::avg('profile_id'))
]; ];
return $stats; return $stats;