
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
- Conditional where clause in Laravel
- Laravel 5.4 save data to database
- Create records using relationship in laravel
- How to get specific columns using Laravel eloquent methods
- After image selected get validation error in laravel
- Undefined property: stdClass::$title
- Laravel delete all rows older than 30 days
- How to add script on specific view file in laravel while extending layout
- How to display HTML tags In Laravel blade
- How to insert dynamic value to additional column in pivot table in laravel
- How to create pivot table in laravel using migration
- Laravel insert query not working
- SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
- Rename Pivot Table in Laravel
- There are no commands defined in the "route:" namespace
- Laravel order by date not working
- How to display pivot table column value in laravel
- Send OTP using textlocal api in laravel
- Get only 10 records from table in laravel
- How to get specific columns using with method in laravel Eloquent relationship
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- How to show data by ID in laravel?
- Calculate age from date of birth in Laravel
- Use withCount() to get total number of records with relationship
- Symlink(): No such file or directory