T
T
Troodi Larson2019-03-20 19:52:02
Laravel
Troodi Larson, 2019-03-20 19:52:02

How does auth middleware work?

Good evening! I looked at the auth middleware and didn't see $next($request) there, why isn't it there? Is it possible to add an else construction where you can update the user's data. More or less like this:

if (!$request->expectsJson()) {
  return route('login');
} else {
  Model::where('user_id', Auth::user()->id)->update(['some' => 'value']);
}

Since there is no $next (probably not in vain), it's a little unclear how to do the after auth middleware.
Or maybe I'm doing it wrong from the point of view of logic?
Well, for any intermediary code:
class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string
     */
    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('login');
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question