For those who don’t want to blindly add middleware to routes, you just need to add classes that manage cookies and sessions to the corresponding middleware group ( apiin my case). For me, these classes are where:
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Session\Middleware\StartSession::class,
Here's how my variable ended App\Http\Kernel::$middleWare:
protected $middlewareGroups = [
'web' => [
...
],
'api' => [
'throttle:60,1',
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Auth\Middleware\Authenticate::class
],
];
Using Laravel 5.3
source
share