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
- How to get specific columns using Laravel eloquent methods
- Calculate age from date of birth in Laravel
- Delete all related comments on deleting a post in Laravel
- How to get images from AWS s3 and display in Laravel blade
- Include External CSS and JS file in Laravel
- Send OTP using textlocal api in laravel
- How to remove package from laravel
- How to get route name on visit URL in laravel
- Call to undefined relationship [user] on model [App\Models\Post]
- Target class [admin] does not exist.
- How to check find method executed successfully in laravel
- The use statement with non-compound name 'DB' has no effect
- How to pass data to route in laravel?
- The POST method is not supported for this route. Supported methods: PUT.
- Laravel 7 login error message not showing
- Split an Eloquent Collection by half in Laravel
- Credit card validation in laravel
- How to display pivot table column value in laravel
- Comment .env file in laravel
- Laravel recursive function in controller
- How to create pivot table in laravel using migration
- Sample configuration files to create laravel project with docker using wsl (window subsystem linux)
- Automatically remove records using Prunable trait in Laravel
- Laravel save object to database
- How to get query string value in laravel