Questions tagged [laravel-session]
101 questions
6
votes
1 answer
PhpUnit and Laravel 5.4 how to mock Session data during a test
I'm testing a class in laravel 5.4 with phpunit that uses the session to get data. Retrieving the session data works when accessing it directly when the app is running aka "session('consumer')" returns a value, however when i try to test a function…

Herchelle Botha
- 63
- 1
- 5
4
votes
2 answers
How to override Session::get?
We need to do custom logic at Session::get like for example, for some reason, if it gets a null value do something else before returning null to the caller..
We had a look at extending the session here but the handler that we need to override is at…

Mohammad AL-Raoosh
- 721
- 1
- 12
- 32
4
votes
4 answers
laravel how to check if session variable is empty
How can I check if this session is empty, here example
@elseif {{Session::get('package_id')}}=null
@include('index.customer.customerpackage')
and how to check if {{Session::get('package_id')}}=1 then Free else Paid
user7456955
3
votes
1 answer
Unable to resolve NULL driver for [Illuminate\Session\SessionManager]
I am using Laravel 5.7. My application is working fine last night. but suddenly this error appears. I did not change any file. Now I am searching for a solution but I did not find any. I am new on laravel I am not familiar with core files of…

muhammad ali
- 33
- 1
- 4
3
votes
3 answers
Laravel custom redirect after Registration with custom flashed session data
I am building an app with Laravel 5.8 where, after registration or login, the user is redirected to a custom page along with a flashed session data, displayed on the page, that says "Welcome!".
I noticed that default redirect behavior in the…

Enrico
- 787
- 12
- 28
2
votes
1 answer
Laravel 8: Session does not apply
I'm in Laravel 8 and I wanted to show an error message to user when he enters wrong credentials for signing into his account at login.blade.php.
So in the Controller, I have this:
if(Auth::attempt($credentials)){
// log user in
}else{
…

Pouya
- 114
- 1
- 8
- 36
2
votes
2 answers
how to session()->forget('cart') for another user in laravel?
my session driver is set to database,
.env => SESSION_DRIVER=database
I have made a model for session and I access to a session of another user by user_id like this :
use App\Models\Session;
$payload = Session::where('user_id',…

aref razavi
- 413
- 2
- 12
2
votes
1 answer
How can I prevent Laravel from setting a session cookie when the user is not auth?
By default, Laravel sets a Cookie called [APP_NAME]_session on every request. It's used for features as redirect()->back().
This cookie prevents my cache mechanism to work properly (FastCGI, Varnish, you name it)
If I'm one hundred percent sure I…

Didier Sampaolo
- 2,566
- 4
- 24
- 34
2
votes
3 answers
Storing User Roles in Session Laravel
Hello there I am working on a project in Laravel in which i need to assign permission to each user so that i could verify on each blade file or controller function to check whether the current user has the permission to perform this. Moreover, the…

Hammad Butt
- 73
- 2
- 7
2
votes
1 answer
Is it possible to use session from kernel console command in laravel?
I'm trying to fetch data from sessions when I run a command in my console, but session always returns an empty array!
php artisan command:mycommand
Below is how I'm trying to get the session:
//returns empty array
$session = session()->all();
Any…

Ricardinho
- 599
- 9
- 22
2
votes
0 answers
Laravel session token create new file
I'm using Laravel session's 'file' driver and adding sessions according to my requirement.
For some reason, I have noticed its creating several consecutive session files per second have data in like this
Session…

Ajit Singh
- 51
- 5
2
votes
0 answers
How to sync session data with API guard in laravel
I'm using laravel 5.8 in E-Commerce application
I need users to add products to cart without login from mobile application, and sync cart data with web after logging-in. so when user logging in from web account he can see his cart items added from…

Ahmed
- 558
- 1
- 4
- 22
2
votes
0 answers
Laravel not setting session, set_cookie is missing from response header
After form submission, it shows "419|page expired." I used @csrf in the form and its working on my local server. However, I am facing the issue on the live server. Any help? I have three types of users and implemented multi auth for them. The form…

Wahidul Alam
- 1,216
- 4
- 26
- 56
2
votes
2 answers
How do I create a Laravel global variable from session data and make available across all views?
I set session data on login in the LoginController like so:
class LoginController extends Controller{
protected function authenticated($request, $user){
$record = ['name'=>'bob'];
session(['profile' => $record]);
}
}
The…

tgrass
- 135
- 3
- 12
2
votes
0 answers
Flash message not visible in Laravel 5.7
flash messages not visible in the view section, after adding these lines in the Kernel.php.
protected $middleware = [
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
…

Vaibhav Singhal
- 511
- 1
- 4
- 25