Laravel Multi-Auth路由问题

时间:2018-07-25 07:27:46

标签: laravel laravel-5

当我在laravel中安装多重身份验证但出现路由问题时。

当地址栏写入时,我正在web.php中进行编辑,

localhost/projectname/admin

但发生错误-找不到页面 但是我通过了这样的特定地址

localhost/projectname/admin/login

在该页面之后打开,但效果不好。 你可以我只通过

localhost/projectname/admin 

在该页面(视图)之后打开?

中间件

protected $routeMiddleware = [
        'admin' => \App\Http\Middleware\RedirectIfNotAdmin::class,
        'admin.guest' => \App\Http\Middleware\RedirectIfAdmin::class,
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    ];

中间件RedirectifNotAdmin.php控制器

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfNotAdmin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = 'admin')
    {
        if (!Auth::guard($guard)->check()) {
            return redirect('admin/login');
        }

        return $next($request);
    }
}

我的路线

Route::get('/admin', 'AdminController@index');

控制器文件 AdminController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */

    public function __construct()
    {
        $this->middleware('auth:admin');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('admin');
    }
}

0 个答案:

没有答案