Here is my route:
Route::controller('/app/{companyId}/', 'HomeController', array('before' => 'auth'));
How can I get the $ companyId argument in __constructor to avoid splitting it in all my actions?
If you want to get the parameters in __construct of your controller, you can do this:
class HomeController extends \BaseController { public function __construct() { $this->routeParamters = Route::current()->parameters(); } }
it will return a list of parameters for the route (for example: ['companyId' => '1']) @see \ the Illuminate \ the Routing \ Route
['companyId' => '1']
You can also get a specific parameter using getParameter () or parameter () .
: , . .
, , , . , , .
Route:: resource. routes.php:
Route::bind('company', 'Company'); Route::resource('company', 'HomeController');
, . , /company/ 1:
public function show($company) { // Here you can use, for instance, $company->name }
Source: https://habr.com/ru/post/1542963/More articles:SignalR Hubs in a class library? Is this a good idea or a bad one? - .netRemove hour from my timestamp - timeChange branch that switches after deployment - gitMarker using path with leading slash - pythonPython Flask - URL encoded leading slashes calling 404 or 405 - pythonHow to save a marker on the road? Google Maps Android - androidUse selenium webdriver as base python - pythonSass variable in quotes for href - cssspring -boot Ρ tomcat ΠΈ cxf-servlet - springCapturing a parameter using lambda - c #All Articles