one of my application pages is loading some content via ajax on my page (currently 2 requests, after the document is ready). Many times I get for this ajax requests the status "401" with the answer "Unauthorized". Sometimes when I refresh the page (with F5), it works, sometimes one request gets the status 401. And the less time I get 500 (laravel in this case uses the wrong database credentials, not from .env).
Can someone help me with these problems?
Using Laravel 5.1.6
thanks
public function handle($request, Closure $next) { if ($this->auth->guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('auth/login'); } } return $next($request); }
source share