1

我刚开始使用 Laravel 框架。我正在观看 youtube 上的教程“如何进行多重身份验证”。一切正常,我可以为两个用户(用户/员工)登录,注册新帐户,但我意识到当凭据不正确(两个用户中的任何一个)它会给我一个错误

This page isn’t working 127.0.0.1 is currently unable to handle this request.
HTTP ERROR 500

注意:有 2 个模型:1) 用户 2) 员工

User Table:
email - xxxx@gmail.com
password - 123456
Staff Table:
email - xxxx@gmail.com
password - 123456

场景 1:当我输入正确的凭据时,它是正确的

Login

Email:xxxx@gmail.com
Password:123456

但是当凭据不正确时

场景 2:不正确的凭据

Login

Email:xxxx@gmail.com
Password:12345

在此处输入图像描述

员工登录控制器

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
class StaffLoginController extends Controller
{
    //
    public function __construct()
    {
        $this->middleware('guest:staff');
    }
    public function showLoginForm()
    {
        return view('auth.staff.login');
        // return view('layouts.staff.app');
    }
    public function login(Request $request)
    {
        // Validate the form
        $this->validate($request,[
            'email'     => "required|email",
            'password'  => 'required|min:6'
        ]);

        // Attempt to log

        if(Auth::guard('staff')->attempt(['email' => $request->email, 'password' => $request->password],$request->remember))
        {
            // If successful, then redirect 
            return redirect()->intended(route('staff.index'));
        } 


        // If unsuccessful, then redirect to login
    }
}

处理程序

public function render($request, Exception $exception)
    {
        // return parent::render($request, $exception);
        $guard =  array_get($exception->guards(),0);
        switch ($guard) {
            case 'staff':
                # code...
                $login = 'staff.login';
                break;

            default:
                # code...
                $login = 'login';
                break;
        }
        return redirect()->guest(route($login));
    }

网络

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');


Route::prefix('staff')->group(function(){
    Route::get('/', 'StaffController@index')->name('staff.index');
    Route::get('/login','Auth\StaffLoginController@showLoginForm')->name('staff.login');
    Route::post('/login','Auth\StaffLoginController@login')->name('staff.login.submit');
});

问题:这个错误的原因是什么?

4

0 回答 0