familytree365 /
backend
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Http\Controllers; |
||
| 4 | |||
| 5 | use App\Models\Permission; |
||
| 6 | use Illuminate\Http\Request; |
||
| 7 | |||
| 8 | class PermissionController extends Controller |
||
| 9 | { |
||
| 10 | public function index() |
||
| 11 | { |
||
| 12 | return auth()->user()->getAllPermissions()->pluck('name'); |
||
| 13 | } |
||
| 14 | |||
| 15 | public function getPermission(Request $request) |
||
| 16 | { |
||
| 17 | $query = Permission::query(); |
||
| 18 | |||
| 19 | if ($request->has('searchTerm')) { |
||
| 20 | $columnsToSearch = ['name']; |
||
| 21 | $search_term = json_decode($request->searchTerm)->searchTerm; |
||
| 22 | if (! empty($search_term)) { |
||
| 23 | $searchQuery = '%'.$search_term.'%'; |
||
| 24 | foreach ($columnsToSearch as $column) { |
||
| 25 | $query->orWhere($column, 'LIKE', $searchQuery); |
||
| 26 | } |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | if ($request->has('columnFilters')) { |
||
| 31 | $filters = get_object_vars(json_decode($request->columnFilters)); |
||
| 32 | |||
| 33 | foreach ($filters as $key => $value) { |
||
| 34 | if (! empty($value)) { |
||
| 35 | $query->orWhere($key, 'like', '%'.$value.'%'); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($request->has('sort.0')) { |
||
| 41 | $sort = json_decode($request->sort[0]); |
||
| 42 | $query->orderBy($sort->field, $sort->type); |
||
| 43 | } |
||
| 44 | |||
| 45 | if ($request->has('perPage')) { |
||
| 46 | $rows = $query->paginate($request->perPage); |
||
| 47 | } |
||
| 48 | if (! count($request->all())) { |
||
| 49 | $rows = $query->get()->toArray(); |
||
| 50 | } |
||
| 51 | |||
| 52 | return $rows; |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 53 | } |
||
| 54 | } |
||
| 55 |