لا يجب وضع custom route بعد resource route

لا يجب وضع custom route بعد resource route

2024-11-23 وقت القراءه : 1 دقائق

Bad Practice Example

Route::resource('recipes', 'RecipeController');
Route::get('recipes/restore/one/{recipe}',
   [\App\Http\Controllers\RecipeController::class,
   'restore'
);
Route::get('recipes/restore_all',
   [\App\Http\Controllers\RecipeController::class,
   'restoreAll'
);

What To Do Instead

Route::get('recipes/restore/one/{recipe}',
   [\App\Http\Controllers\RecipeController::class,
   'restore'
);
Route::get('recipes/restore_all',
   [\App\Http\Controllers\RecipeController::class,
   'restoreAll'
);
Route::resource('recipes', 'RecipeController');

اذا كنت تستخدم route::resource ويوجد route أخرى تؤدي إلى نفس الـ controller، فإنه يجب وضعها قبل route::resource.

إضافة تعليق
Loading...