
Route group with URI prefix using middleware and route name prefixes
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.phpRoute::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.phpRoute::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.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
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.
Random Code Snippet Queries: Laravel
- Extract only time from datetime in laravel
- How to add dynamic page title in Laravel view
- Non-static method App\Http\Helper::myFunction() should not be called statically
- How to add foreign key in laravel using migration
- How to display pivot table column value in laravel
- Redirect from www to non www in laravel using htaccess
- Validation for multiple forms on same page in laravel
- How to call controller function from view in Laravel
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- How to get images from AWS s3 and display in Laravel blade
- How to get route name on visit URL in laravel
- Create record with unique slug in laravel
- Insert data with form validation using ajax in laravel
- Conditional validation in laravel
- How to display a specific word from a string in laravel
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- Wheredate in laravel not working
- Get ids in array from users table
- How to create laravel project using jetstream
- Display option of select as selected with blade directive Laravel
- Call to undefined relationship [user] on model [App\Models\Post]
- File_put_contents(/var/www/html/w3code/storage/framework/sessions/CXwN3EXKxERD6jgy3rADcaAAbAx8FRKih2JK7UO9): Failed to open stream: Permission denied
- Get duplicate records in laravel
- The POST method is not supported for this route. Supported methods: PUT.
- How to check query string exists or not in laravel blade