Route group with URI prefix using middleware and route name prefixes

Using route group you can create a web route group with a specific URI prefix using the auth middleware with route name prefixes.

Answers 2
  • Route group with URI prefix using auth middleware and route name prefixes

    --PATH routes\web.php
    Route::group(['prefix' => 'admin','middleware' => ['auth'], 'as'=> 'admin.'], function () {
        Route::get('dashboard', [App\Http\Controllers\AdminController::class, 'index'])->name('dashboard');
    });
    
    0

    You can visit the specified web route https://domain.com/admin/dashboard with route name admin.dashboard if the user is authenticated. Each route will be visited if the user is authenticated with url prefix /admin with common route name admin.routename.

  • Route group with URI prefix using middleware auth and admin with route name prefixes

    --PATH routes\web.php
    Route::group(['prefix' => 'admin','middleware' => ['auth','admin'], 'as'=> 'admin.'], function () {
        Route::get('dashboard', [App\Http\Controllers\AdminController::class, 'index'])->name('dashboard');
        Route::resource('seller', App\Http\Controllers\SellerController::class);
    });
    
    0

    You can visit the specified web route https://domain.com/admin/dashboard with route name admin.dashboard if the user is authenticated and the user is an admin. Each route will be visited if the user is authenticated and the user is an admin with url prefix /admin with common route name admin.routename.

  • Back to code snippet queries related laravel