Laravel 5.3 - How to add Sessions to `API` without CSRF?
go to app/Http/Kernel.php and add your own name like 'sessions' to the $middlewareGroups. It should contain \Illuminate\Session\Middleware\StartSession::class,
Assign 'sessions' to those routes you want.
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'api' => [
'throttle:60,1',
],
'sessions' => [
\Illuminate\Session\Middleware\StartSession::class,
]
];
routes/api.php
Route::group(['middleware' => ['sessions']], function () {
Route::resource(...);
});
Laravel - Session store not set on request
You'll need to use the web middleware if you need session state, CSRF protection, and more.
Route::group(['middleware' => ['web']], function () {
// your routes here
});
Session store not set on request in Laravel 5.3
You'll need to use the web middleware if you need session state, CSRF protection, and more.
Route::group(['middleware' => ['web']], function () {
// your routes here
});
your kernel.php should look like this
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Session\Middleware\StartSession::class,
];
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\anlutro\LaravelSettings\SaveMiddleware::class,
\Barryvdh\Cors\HandleCors::class,
Activated::class
],
Related Topics
Flex/Grid Properties Are Deleted in Gmail Email
PHP Sort($Array) Returning 1 Instead of Sorted Array
Add New Data into PHP JSON String
How to Integrate PHPmailer with Codeigniter 3
What Do \R and \N Mean in PHP (And Other Languages)
Ignoring Errors in File_Get_Contents Http Wrapper
How to Have Multiple $_Get with the Same Key, Different Values
Extract Dom-Elements from String, in PHP
Warning Problem: Expects Parameter 1 to Be MySQLi_Result
How to Check If File Is Ascii or Binary in PHP
PHP Pthreads: Fatal Error: Class 'Thread' Not Found
How to Use MySQLi_Fetch_Object with a Prepared Statement
Best Method for Converting a PHP Array to JavaScript