Closed amirhosseindz closed 6 years ago
@amirhosseindz Why do you want to do the stuff in the built in middleware? Why can't you do it a separate one? The preferred way of accessing the user is this: $request->user()
In the middleware where you have the user.
I'm using nwidart/laravel-modules and I have a lot of modules in the project. So I don't want to edit each module and all of their routes to add a separate middleware. Thus I thought I could just edit that built in middleware which already used every where.
Anyway, I found a solution myself. I extended that built in middleware class to my custom middlware class and did my stuff there. Then I set its alias api.auth
to point to that custom middlware. I did this alias overriding in a service provider.
I need to set some configs and other stuff related to current user, before any request get handled. If I'm correct 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 calledapi.auth
to do this. Its usage on my routes is like this:But I don't have any access to it cause it's a builtin middleware. So what should I do in this situation?