Q: Laravel sub-domain routing set global para for route() helper I have setup sub-domain routing on my app (using Laravel 5.4) with the following web.php route:
Route::domain('{company}.myapp.localhost')->group(function () {
  // Locations
  Route::resource('/locations' , 'LocationController');

  // Services
  Route::resource('/services' , 'ServiceController');
});

However as my show and edit endpoints require an ID to be passed, using a normal route('services.show') helper results in an ErrorException stating Missing required parameters for [Route: services.create] [URI: services/create].
I appreciate this is necessary, but as the company is associated to the user on login (and is in the sub-domain) I don't want to be passing this for every view. I want to set this at a global level.
To avoid repeated queries, I thought about storing this in the session as so (in the :
protected function authenticated(Request $request, $user)
{
    $current_company = $user->companies->first();
    $company         = [
        'id'           => $current_company->id,
        'name'         => $current_company->name,
        'display_name' => $current_company->display_name
    ];
    $request->session()->put('company', $company);
}

Which is fine, but I wonder if I can pass this to the route as a middleware or something. What's be best solution here?

A: Recommendation: remove the slash before the resource name.
The resource method will produce the following URIs:
/services/{service}

So, you should define your routes like this:
Route::domain('{company}.myapp.localhost')->group(function () {
    // Locations
    Route::resource('locations' , 'LocationController');

    // Services
    Route::resource('services' , 'ServiceController', ['only' => ['index', 'store']]);
    Route::get('services');
});


A: I ran into this exact issue today, I poked around in the source and found a defaults method on the url generator that allows you to set global default route parameters like so:
app('url')->defaults(['yourGlobalRouteParameter' => $value]);
This will merge in whatever value(s) you specify into the global default parameters for the route url generator to use.
