If you want to create route grouping based on your sub-domain, This post will help you to make your routing how to make grouping based on a sub-domain. This is very to understand this and setup in your route file.
If you wish to make your routing group based on a sub-domain for the make panel and front site separate. like the main domain for the front website and the admin panel for the sub-domain, so you do it very simply by referring to this post.
How to group routes based on sub-domain?
Route::domain('{sub_domain}.example.com')->group(function () {
Route::get('user/{id}', function ($sub_domain, $id) {
// YOUR CONTROLLER LOGIC GOES HERE
});
});
Prefix Url
You can call a method prefix, using the prefix route method you can apply any prefix URL path to the app that grouping routes.
Route::prefix('admin')->group(function () {
Route::get('user',[HomeController::class,index]);
});
Prefix Route
In case, if you want to give a prefix route name for the specific route groups, you can call the name route method in the route grouping.
Route::name('admin.')->group(function () {
Route::get('user',[HomeController::class,index])->name('dashboard');
});
Call Middleware
If you want to call specific middleware to the route grouping using the middleware method you can use it, This method also accepts the array, so you can check more then one middleware.
Route::middleware(['auth.check'])->group(function () {
Route::get('user',[HomeController::class,index])->name('dashboard');
});
Create Custom Route File With New Service Provider Laravel 8 9
Laravel Routing Multiple Method Use In Single Route
Route Resource Controller Laravel
We always thanks to you for reading our blogs.
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- How to Generate PDF File Using DomPDF In Laravel 9 Example
- Default index.php Root Path Change And Remove Public From The Url
- Trying to access array offset on value of type int
- The GET method is not supported for this route. Supported methods: PATCH
- How To Add Active Class To Menu Item In Laravel
- How to Send Email with Laravel 10
- Select2 ajax example
- How To File Upload AWS s3 Bucket In Laravel 9
- How to hide image URL from IMG tag src laravel
- Looping Variable Laravel Blade File - $loop