Hello, Amathon
I think the problem you are having comes from the 'auth' middleware's behaviour. If you take a look inside it, you will see that non-authenticated users are simply redirected to the '/login' page. In your case, it means that if you are not logged in, redirect()->back() never fires.
A simple way to fix this is to use a custom middleware, which you create. The only real thing you would have to change in it is the handle() method like this:
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->back();
}
}
return $next($request);
}
The result would be that for both authenticated users and guests, you will be doing a redirect back. The difference is that for guests, the article will not be marked, as the middleware will not allow that.
Hope that helps! Good luck!