seperate the relation loading
This commit is contained in:
@@ -9,33 +9,27 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoadPatrolReportService
|
||||
{
|
||||
public function supervisorCartableReport(Request $request)
|
||||
public function supervisorCartableReport(Request $request, $loadRelations = false)
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'start_lat', 'start_lon', 'end_lat', 'end_lon', 'operator_id', 'created_at',
|
||||
'operator_name', 'officer_plaque', 'officer_phone_number', 'officer_name',
|
||||
'supervisor_description', 'supervising_time', 'supervisor_name', 'status',
|
||||
'status_fa', 'distance', 'province_id', 'province_fa', 'edare_id', 'edare_name',
|
||||
'start_time', 'end_time','description', 'cmmsMachines.machine_code', 'rahdaran.code',
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
$allowedFilters = ['*'];
|
||||
$allowedSortings = ['*'];
|
||||
|
||||
$user = auth()->user();
|
||||
$query = null;
|
||||
|
||||
if ($user->hasPermissionTo('show-road-patrol-supervise-cartable')) {
|
||||
$query = RoadPatrol::query()
|
||||
->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']);
|
||||
->select([])
|
||||
->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()
|
||||
->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])
|
||||
->where('province_id', '=', $user->province_id);
|
||||
->select([])
|
||||
->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(
|
||||
@@ -47,20 +41,15 @@ class RoadPatrolReportService
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request)
|
||||
public function operatorCartableReport(Request $request, $loadRelations = false)
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'start_lat', 'start_lon', 'end_lat', 'end_lon', 'officer_plaque', 'created_at',
|
||||
'officer_phone_number', 'officer_name', 'supervisor_description', 'supervising_time',
|
||||
'supervisor_name', 'status', 'status_fa', 'distance', 'start_time', 'end_time', 'cmmsMachines.machine_code', 'rahdaran.code',
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
$allowedFilters = ['*'];
|
||||
$allowedSortings = ['*'];
|
||||
|
||||
$query = RoadPatrol::query()
|
||||
->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])
|
||||
->where('operator_id', '=', auth()->user()->id);
|
||||
->select([])
|
||||
->where('operator_id', '=', auth()->user()->id)
|
||||
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
|
||||
Reference in New Issue
Block a user