|  | 
|  | 1 | +<?php | 
|  | 2 | + | 
|  | 3 | +namespace App\Http\Controllers\Admin; | 
|  | 4 | + | 
|  | 5 | +use App\Http\Controllers\Controller; | 
|  | 6 | +use App\Models\User; | 
|  | 7 | +use Spatie\QueryBuilder\QueryBuilder; | 
|  | 8 | + | 
|  | 9 | +class ManageUserController extends Controller | 
|  | 10 | +{ | 
|  | 11 | + | 
|  | 12 | + | 
|  | 13 | + /*********************************** | 
|  | 14 | + * Start THIS IS A Manage User - Controller * | 
|  | 15 | + ***********************************/ | 
|  | 16 | + | 
|  | 17 | + | 
|  | 18 | + /** | 
|  | 19 | + * ManageUserController | 
|  | 20 | + * | 
|  | 21 | + * @return void | 
|  | 22 | + */ | 
|  | 23 | + | 
|  | 24 | + | 
|  | 25 | + public function index() { | 
|  | 26 | + | 
|  | 27 | + $data['columns'] = $columns = collect([ | 
|  | 28 | + ['key' => 'sr', 'label' => 'Sr.', 'sortable' => false, 'searchable' => false], | 
|  | 29 | + ['key' => 'username', 'label' => 'USER ID ', 'sortable' => true, 'searchable' => false, 'show' => true], | 
|  | 30 | + ['key' => 'first_name', 'label' => 'First Name ', 'sortable' => true, 'searchable' => false, 'show' => true], | 
|  | 31 | + ['key' => 'last_name', 'label' => 'Last Name ', 'sortable' => true, 'searchable' => false, 'show' => true], | 
|  | 32 | + ['key' => 'email', 'label' => 'Email', 'sortable' => true, 'searchable' => false, 'show' => true], | 
|  | 33 | + ['key' => 'mobile', 'label' => 'Phone', 'sortable' => true, 'searchable' => false, 'show' => true], | 
|  | 34 | + ['key' => 'created_at', 'label' => 'Joined At', 'sortable' => true, 'searchable' => false, 'show' => true], | 
|  | 35 | + ]); | 
|  | 36 | + $globalSearch = getGlobalSearchFilter(['username', 'email', 'mobile']); | 
|  | 37 | + | 
|  | 38 | + $query = QueryBuilder::for(User::class) | 
|  | 39 | + ->defaultSort('-id') | 
|  | 40 | + ->allowedSorts($columns->map->key->all()) | 
|  | 41 | + ->allowedFilters([...$columns->map->key->all(), $globalSearch]); | 
|  | 42 | + | 
|  | 43 | + if (request()->has('exportToExcel') && request()->wantsJson()) { | 
|  | 44 | + return $query->get(); | 
|  | 45 | + } else { | 
|  | 46 | + $data['items'] = $query->paginate(request()->perPage ?? getPaginate())->withQueryString(); | 
|  | 47 | + } | 
|  | 48 | + | 
|  | 49 | + | 
|  | 50 | + $data['pageTitle'] = "All Users"; | 
|  | 51 | + | 
|  | 52 | + return inertia('Admin/User/Index', [ | 
|  | 53 | + 'data' => $data, | 
|  | 54 | + ]); | 
|  | 55 | + } | 
|  | 56 | + | 
|  | 57 | + /*********************************** | 
|  | 58 | + * End THIS IS A ManageUser Controller * | 
|  | 59 | + ***********************************/ | 
|  | 60 | + | 
|  | 61 | +} | 
0 commit comments