I am developing stateless resful API application, so I do not need sessions at all.
I removed a line with \Illuminate\Session\Middleware\StartSession::class,
from protected $middleware = [];
in \app\Http\Kernel.php
I have also removed SESSION_DRIVE
from .env
file. But I am getting following error:
RuntimeException in Request.php line 756: Session store not set on request.
How can I turn off sessions in Laravel 5?
$request->session()->forget('key'); Use flush() method instead of forget() method to delete all session data. Use the pull() method to retrieve data from session and delete it afterwards.
The correct syntax for this is: Session::set('variableName', $value); For Laravel 5.4 and later, the correct method to use is put : Session::put('variableName', $value);
Laravel session is a way of storing the user information across the multiple user requests. It keeps track of all the users that visit the application. Let's understand the session through an example. First, we create a form on which we apply the properties of the session.
By default in laravel application session timeout value is 120 minutes.
Remove the Illuminate\Foundation\Http\Middleware\VerifyCsrfToken
and Illuminate\View\Middleware\ShareErrorsFromSession
classes from your middleware too. These features require sessions.
Not required but I'd also probably suggest setting your session driver to array
, just so that if any features you are using require the sessions feature they can at least work without throwing errors. The array driver, as it suggests, stores all the session data in a standard PHP array so everything is erased as soon as the request is completed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With