Niroj Adhikary
Niroj Adhikary

Reputation: 1835

How to pass one variable in every route by default?

I am working with wildcard sub domain.And i have defined route and its name like

Route::group(['domain'=>'{subdomain}.'.config('app.url')], function(){
    Route::resource('dashboard', 'Dashboard', ['as'=>'school']);
});

While redirecting it using route name redirect(route('school.dashboard.index')) it says Missing required parameters for... if i pass variable same route name likeredirect(route('school.dashboard.index', 'subdomainname')) it works perfect. Here i have to pass subdomain in each and every redirect using route name. What i want to do is, i want to pass that variable by default in every route name. How can i do this?

Upvotes: 2

Views: 72

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163898

In methods of DashboardController, you need to do something like this:

public function index($subdomain)

Instead of just:

public function index()

https://laravel.com/docs/5.5/routing#route-group-sub-domain-routing

And when you're using helpers like route() to create links, pass subdomain too:

redirect(route('school.dashboard.index', ['subdomain' => $subdomain]))

Upvotes: 1

Related Questions