user(); $query = null; if ($user->hasPermissionTo('show-road-patrol-supervise-cartable')) { $query = RoadPatrol::query() ->select([ 'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description', 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points' ]) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); } elseif ($user->hasPermissionTo('show-road-patrol-supervise-cartable-province')) { if (is_null($user->province_id)) { return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); } $query = RoadPatrol::query() ->select([ 'province_fa', 'province_id', 'id', 'edare_id', 'edare_name', 'start_time', 'end_time', 'created_at', 'description', 'distance', 'vehicle_runtime', 'fuel_consumption', 'stop_points' ]) ->where('province_id', '=', $user->province_id) ->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])); } $data = DataTableFacade::run( $query, $request, allowedFilters: $allowedFilters, allowedSortings: $allowedSortings); return $data; } }