Answers for "how to redirect back to admin page if user is not authenticated in laravel based on the guard"

PHP
1

how to redirect back to admin page if user is not authenticated in laravel based on the guard

Redirect unauthenticated user according to their guards
  
Change your Authenticate middleware to this
  
  <?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Support\Arr;

class Authenticate extends Middleware
{
    protected $guards;

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string[]  ...$guards
     * @return mixed
     *
     * @throws \Illuminate\Auth\AuthenticationException
     */
    public function handle($request, Closure $next, ...$guards)
    {
        $this->guards = $guards;

        return parent::handle($request, $next, ...$guards);
    }

    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string|null
     */
    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            if (Arr::first($this->guards) === 'admin') {
                return route('admin.login');
            }

            return route('login');
        }
    }
}
Posted by: Guest on January-24-2021
0

Route::auth(); giving error in laravel 7

Do this step from the upgrade guide 
https://laravel.com/docs/7.x/upgrade#authentication-scaffolding

############
composer require laravel/ui "^2.0"
Posted by: Guest on November-10-2020
0

how to redirect back to admin page if user is not authenticated in laravel based on the guard

Redirect unauthenticated user according to their guards
Posted by: Guest on January-24-2021

Code answers related to "how to redirect back to admin page if user is not authenticated in laravel based on the guard"

Browse Popular Code Answers by Language