I'm new to using Laravel 8. In previous Laravel version 7, we can pass subdomain name with this way
Route::group( [ 'domain' => '{admin}.example.com' ], function () {
Route::get('/index', 'HomeController@index($account)' );
}
But, in Laravel 8 structure code to call Controller was changed like this.
Route::domain('{admin}.example.com')->group(function () {
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
});
I've been looking for the docs but have not found them. Can you show me docs or helping me to send / passing subdomain from web.php to Controller
You can simply add a parameter to your controller method with the same name as the route parameter. Laravel takes care of binding the variable behind the scenes.
It's not explicitly shown in the docs with reference to controllers, but there is a basic example. https://laravel.com/docs/8.x/routing#route-group-subdomain-routing
Below is an example with a controller.
Route::domain('{subdomain}.example.com')->group(function () {
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
});
class HomeController
{
public function index($subdomain)
{
dd($subdomain);
}
}
://admin.example.com/home
"admin"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With