Route group with URI prefix using middleware and route name prefixes

Created at 14-Jul-2021 , By samar

Route group with URI prefix using middleware and route name prefixes

In this article, we will see how to solve "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.
  • 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');
    });
    

    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);
    });
    

    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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.