I have a middleware for setting the locale of my laravel application by getting the value from the session before each and every request.
I have a route that sets this variable,and I apply this middleware to all routes,including this one.
Here is my middleware:
* Handle an incoming request.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
public function handle($request, Closure $next)
public function setLang(string $lang)
I finally found an answer for that.
The middleware responsible for starting sessions is not a global middleware,it is only in the
web middleware group.Therefore,laravel was unable to access the session ,since my middleware was run before they were even started.