From a643bdf626566a367e5ad352b43e0576db59edcc Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 12 Apr 2025 15:06:50 +0330 Subject: [PATCH] debug the index method --- .../RoadMaintenanceStationController.php | 36 ++++++++----------- routes/v3.php | 16 +++------ 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php index 7b1069ab..28d3a078 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php @@ -38,12 +38,10 @@ class RoadMaintenanceStationController extends Controller $query = RahdariPoint::with('files') ->when($status, fn ($query, $status) => $query->where('status', $status)) - ->when($type, fn ($query, $type) => $query->where('type', $type)); + ->when($type, fn ($query, $type) => $query->where('type', $type)) + ->when($province, fn($query, $province) => $query->where('province_id', $province)); - if ($user->can('show-tollhouse')) { - $query->when($province, fn($query) => $query->where('province_id', $province)); - } - elseif ($user->can('show-tollhouse-province')) { + if ($user->hasPermissionTo('show-tollhouse-province')) { $query->where('province_id', $user->province_id); } @@ -56,27 +54,23 @@ class RoadMaintenanceStationController extends Controller foreach ($data['data'] as &$stations) { - if ($user->can('edit-tollhouse')) { + if ($user->hasPermissionTo('edit-tollhouse')) { $stations['canEdit'] = 1; - } elseif ($user->can('edit-tollhouse-province')) { - if ($user->province_id) { - $stations['canEdit'] = 1; - } else { - $stations['canEdit'] = 0; - } - } else { + } + elseif ($user->hasPermissionTo('edit-tollhouse-province') && $stations->province_id == $user->province_id) { + $stations['canEdit'] = 1; + } + else { $stations['canEdit'] = 0; } - if ($user->can('delete-tollhouse')) { + if ($user->hasPermissionTo('delete-tollhouse')) { $stations['canDelete'] = 1; - } elseif ($user->can('delete-tollhouse-province')) { - if ($user->province_id) { - $stations['canDelete'] = 1; - } else { - $stations['canDelete'] = 0; - } - } else { + } + elseif ($user->hasPermissionTo('delete-tollhouse-province') && $stations->province_id == $user->province_id) { + $stations['canDelete'] = 1; + } + else { $stations['canDelete'] = 0; } } diff --git a/routes/v3.php b/routes/v3.php index 28207829..54aa3439 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -392,15 +392,9 @@ Route::prefix('Road-Maintenance-Station') ->name('Road-Maintenance-Station.') ->controller( RoadMaintenanceStationController::class) ->group(function () { - Route::get('/', 'index')->name('index') - ->middleware('permission:show-tollhouse|show-tollhouse-province'); - Route::post('/', 'store')->name('store') - ->middleware('permission:add-tollhouse|add-tollhouse-province'); - Route::get('/{rahdariPoint}', 'show')->name('show') - ->middleware('permission:show-tollhouse|show-tollhouse-province'); - Route::post('/{rahdariPoint}', 'update')->name('update') - ->middleware('permission:edit-tollhouse|edit-tollhouse-province'); - Route::delete('/{rahdariPoint}', 'destroy')->name('destroy') - ->middleware('permission:delete-tollhouse|delete-tollhouse-province'); - + Route::get('/', 'index')->name('index')->middleware('permission:show-tollhouse|show-tollhouse-province'); + Route::post('/', 'store')->name('store')->middleware('permission:add-tollhouse|add-tollhouse-province'); + Route::get('/{rahdariPoint}', 'show')->name('show')->middleware('permission:show-tollhouse|show-tollhouse-province'); + Route::post('/{rahdariPoint}', 'update')->name('update')->middleware('permission:edit-tollhouse|edit-tollhouse-province'); + Route::delete('/{rahdariPoint}', 'destroy')->name('destroy')->middleware('permission:delete-tollhouse|delete-tollhouse-province'); });