create and change code
This commit is contained in:
@@ -26,50 +26,17 @@ class RoadMaintenanceStationController extends Controller
|
||||
$user = auth()->user();
|
||||
$user->addActivityComplete(1019);
|
||||
|
||||
$province = $request->province;
|
||||
$status = $request->status;
|
||||
$type = $request->type;
|
||||
|
||||
$query = RahdariPoint::query()
|
||||
->when($status, fn ($query, $status) => $query->where('status', $status))
|
||||
->when($type, fn ($query, $type) => $query->where('type', $type))
|
||||
->when($province, fn($query, $province) => $query->where('province_id', $province));
|
||||
->when($user->hasPermissionTo('show-tollhouse-province') && !$user->hasPermissionTo('show-tollhouse'),
|
||||
fn ($query) => $query->where('province_id', $user->province_id)
|
||||
);
|
||||
|
||||
if ($user->hasPermissionTo('show-tollhouse-province') && !$user->hasPermissionTo('show-tollhouse')) {
|
||||
$query->where('province_id', $user->province_id);
|
||||
}
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
return response()->json(DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*']
|
||||
);
|
||||
|
||||
|
||||
foreach ($data['data'] as &$stations) {
|
||||
if ($user->hasPermissionTo('edit-tollhouse')) {
|
||||
$stations['canEdit'] = 1;
|
||||
}
|
||||
elseif ($user->hasPermissionTo('edit-tollhouse-province') && $stations->province_id == $user->province_id) {
|
||||
$stations['canEdit'] = 1;
|
||||
}
|
||||
else {
|
||||
$stations['canEdit'] = 0;
|
||||
}
|
||||
|
||||
if ($user->hasPermissionTo('delete-tollhouse')) {
|
||||
$stations['canDelete'] = 1;
|
||||
}
|
||||
elseif ($user->hasPermissionTo('delete-tollhouse-province') && $stations->province_id == $user->province_id) {
|
||||
$stations['canDelete'] = 1;
|
||||
}
|
||||
else {
|
||||
$stations['canDelete'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user