M
M
mrSeller2018-03-28 09:46:12
Laravel
mrSeller, 2018-03-28 09:46:12

Why does the session check in the middleware return false, while in the template it returns true?

It is not necessary to register on the site, but it is very important to know the user's city in order to provide relevant content.
Therefore, in the global middleware, I define the city using https://api.sypexgeo.net/json/, look for it in the database and fix it in the session: Session::put('city', $city)
In order not to send repeated requests to api.sypexgeo.net, I check before it: if (!Auth::check() && !session()->has('city')) {}
And it turned out that the session always returns false here, as if it is not open session with the city, but when I check in the template, the check for the presence of the session returns true.
How then to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2018-03-28
@mrSeller

Most likely your middleware is in the array of global middlewares higher than StartSession

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question