A
A
Alexander Pankov2018-12-10 19:40:58
Laravel
Alexander Pankov, 2018-12-10 19:40:58

Why does laravel create a new session on every request?

Hello, I am trying to save data in a session

$data = \request()->session()->all(); // тут только _token и он каждый раз новый
$arCart = self::getCart(); // тут пусто
$arCart[$id] = (isset($arCart[$id]) ? $arCart[$id] : 0) + $quantity;
session(['cart' => $arCart]);
$arCart = self::getCart();  // тут уже не пусто

The data is stored in the session, it is saved, but when I refresh the page everything disappears, or when I click the "add" button again, which sends a request to add a product, the session becomes empty again, more precisely, a new one is created,
why maybe? how do i save the session correctly?
and also no POST request works for me, 419 error is always returned until I did it in the app/Http/Middleware/VerifyCsrfToken.php file
like this (they removed cross-domain protection, with POST requests I definitely sent this key in the headers, but not all equal to 419 received)
protected $except = [
    '/*'
];

laravel 5.7

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2018-12-10
@JhaoDa

Because you need to check that the session is being written (write permissions to the directory if the driver is file) and the session cookie is being set. The question has already been asked and answered a million times on Google.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question