I use Laravel 4 to create API names labeled accountname for each of my clients. Each client has its own identical database. Therefore, Foocorp should make api calls that look like this:
http://api.example.com/Foocorp/users/5
The call to Barcorp api is as follows
http://api.example.com/Barcorp/users/5
I have to provide the account name in the URL for business / branding reasons, so I cannot remove this parameter from the URL routes.
Here is the filter that I used to try to get the account name out of the route, check its activity and point to my database. I was hoping to remove the accountname parameter so that I could write all my controller functions so as not to include the $accountname parameter for all of them.
Route::filter('accountverification', function() { $route = Route::getCurrentRoute(); $params = $route->getParameters(); $accountName = $params['accountname'];
Here is my route group that uses a filter:
Route::group(array('prefix' => '{accountname}', 'before' => 'accountverification'), function() { Route::get('users/{id}', ' UsersController@getShow ') ->where(array('id' => '[0-9]+')); });
The problem is that deleting a parameter in the filter has no effect when calling the controller / function. In the UsersController :: getShow function, the first parameter is always accountname from the group prefix.
Is there a way to include a variable / parameter in all my routes so that I can do something before sending a request that will not be passed to the function?
source share