Laravel / Route / Grouping in route
Grouping in route
-
STEP
1. add prefix in front of each url
without grouping
Route::get('admin/student', [App\Http\Controllers\StudentController::class, 'index'] ); Route::get('admin/student/create', [App\Http\Controllers\StudentController::class, 'create'] ); with grouping
# Prefix routes with admin and group them together Route::prefix('admin')->group(function() { Route::get('student', [App\Http\Controllers\StudentController::class, 'index'] ); Route::get('student/create', [App\Http\Controllers\StudentController::class, 'create'] ); }); groups with middlewares
# Group routes that are public only can be accessed without user is logged on Route::middleware(['web'])->group(function () { Route::get('student', [App\Http\Controllers\StudentController::class, 'index'] ); Route::get('student/create', [App\Http\Controllers\StudentController::class, 'create'] ); });