Check
Route::current()->parameter('company')
Perhaps a variable there is. This code can be called anywhere.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm attempting to create a set of resourceful routes which are prefixed with a wildcard subdomain associated to an account/company.
The issue I have is when I use the route() helper it requires the account/company to be passed as a second parameter (which I'd rather not set in each view).
Equally, I'd like to have the $current_company set globally so I can access it within each of the controllers for eloquent queries etc.
What is the best approach to set this variable once (perhaps on login by the authenticated() method?) and to have it globally accessible? I've considered a service provider, middleware but (as I'm relatively new to Laravel) I'm not sure on the best approach.
I'm using Laravel 5.4. This is my web.php routes file:
Route::domain('{company}.appointments.localhost')->group(function () {
// Home
Route::get('/home', 'HomeController@index')->name('home');
// Companies
Route::resource('companies' , 'CompanyController');
// Locations
Route::resource('locations' , 'LocationController');
// Services
Route::resource('services' , 'ServiceController');
// Bookings
Route::resource('bookings' , 'BookingController');
});
Happy to provide any additional details if it will aid answering the question. Thanks in advance!
Please or to participate in this conversation.