
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 add columns in existing table using migration in laravel
- On delete set foreign id column value null using migration in laravel 8
- How to get date from created_at field in laravel
- Delete file from amazon s3 bucket using Laravel
- Create record with unique slug in laravel
- Get duplicate records in laravel
- Class 'App\Rules\Hash' not found in Laravel
- Attempt to read property "avatar" on null in Laravel
- How to create pivot table in laravel using migration
- Count all and get 10 records after where condition in laravel
- How to remove package from laravel
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- Display message with session flash using bootstrap alert class in laravel
- Laravel csrf token mismatch for ajax POST Request
- Laravel URL validation not working
- How to get file extension from input type file in laravel
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- Create project table with model and migration
- Update email with unique validation in laravel
- How to upload image in laravel 8
- Get last year created records in Laravel
- Create model with migration and seeder
- How to call controller function from view in Laravel
- How to avoid duplicate entries in pivot table in Laravel
- How to pass query string to url in laravel