In a fully restful Laravel project, I'm using dingo/api
package. I need to set some configs and other stuff related to current user, before any request get handled. When we using dingo, we can access the current user like this:
$user = app('Dingo\Api\Auth\Auth')->user();
First I thought that I should do this in a service provider. But in there the Laravel has not yet initiated the dingo authenticating, therefore it's throw me an error. Then I thought I need to edit the dingo auth middleware called api.auth
to do this. Its Usage on my routes is like this:
<?php
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['prefix' => 'v1', 'namespace' => 'App\Http\Controllers'], function ($api) {
$api->group(['prefix' => 'admin', 'middleware' => 'api.auth'], function ($api) {
$api->get('checkRole/{branch_id}', 'RoleController@getRoles');
But I don't have any access to it because it's a builtin middleware in dingo package. So what should I do in this situation?