samedi 22 mars 2014

Get parameters for resource controller that has parameter in its base path too


Vote count:

0




I have a route for a resource controller that has a base path. In this base path there is another parameter I need: {countryId}.



Route::resource('country/{countryId}/region', 'CountryRegionController');


I know that in a regular resource controller I can get the resource's id as the function parameter, like this:



public function edit($countryRegionId)
{

}


But that is kinda messed up with the extra parameter in the route. How can I get all parameters in a conventional way?



asked 2 mins ago

totymedli

3,333

1 Answer



Vote count:

0




In this case you can expand your parameter list. Actually you should expand, because if you use only one parameter that will be the value of the parameter in the base route not the id of the resource. So here is the correct way to do this.



public function edit($countryId, $countryRegionId)
{

}


Parameter name can be anything it doesn't have to match with the parameter names in the route, but the order is important.


You could also use Request::segment() but the previous solution is much better.



$countryId = Request::segment(2);
$countryRegionId = Request::segment(4);


answered 2 mins ago

totymedli

3,333




Aucun commentaire:

Enregistrer un commentaire