Currently I'm using this routing format for my custom level views:
Route::group(['prefix' => 'customers/{customer_id}'], function(){
Route::group(['prefix' => 'orders'], function(){
Route::get('/', 'controllers\EndUser\Accounting\OrderController@getList');
Route::get('/{id}', 'controllers\EndUser\Accounting\OrderController@getView');
});
});
If you notice, I'm using a global 'customer_id' and for my sub pages I use a 'id'. I need to pass the 'customer_id' to every controller and every function in the controller, what would be the cleanest way of doing this?
Add the parameters to the controllers that use them.
<?php
class OrderController extends BaseController {
public function getList($customer_id = false)
{
echo 'getList()<br />';
echo 'customer id = '.$customer_id;
}
public function getView($customer_id = false, $id = false)
{
echo 'getView()<br />';
echo 'customer id = '.$customer_id.'<br />';
echo 'id = '.$id;
}
}
?>
Laravel automatically makes route parameters available to the controller functions.