Laravel auth:api middleware does not work with newly created route files
P粉983021177
P粉983021177 2023-09-01 14:46:06
0
1
421
<p>I have a web application using Laravel 7. On the application, I recently created a new api.php file under a folder called <code>api/v2</code> (<code>routes/api/v2/api.php< /code>). The problem I am facing is that in the newly created api.php file the 'auth:api' middleware is not working. </p> <p>I checked the request headers and found that the <code>authorization</code> header for these routes was empty. With the old routing files, everything works fine. </p> <p>I have registered the new api file in RouteServiceProvider.php as shown below</p> <pre class="brush:php;toolbar:false;">Route::prefix('api/v2') ->middleware('api') ->namespace($this->namespace) ->group(base_path('routes/api/v2/api.php'));</pre> <p>Except for the authentication issue, all routing is working fine without any issues. Since I cannot call the '$request->user()' method inside the controller. </p> <p>PS: I am using apache 2.4 </p> <p>Does anyone know why this is happening? </p>
P粉983021177
P粉983021177

reply all(1)
P粉466290133

Can you share your route file? Here's what I tried to do that worked equally well:

protected function mapAdminApiRoutes()
{
    Route::prefix('api/admin')
         ->middleware(['api','jwt.verify','role:admin'])
         ->namespace($this->namespace.'\Admin')
         ->group(base_path('routes/admin-api.php'));
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template