我刚刚开始使用Laravel框架。我正在观看youtube上的教程“如何进行多重身份验证”。一切正常,我可以同时登录两个用户(用户/职员),注册新帐户,但我意识到当凭据不正确(两个用户中的任何一个)时,它将给我一个错误
<form id="moneyform">
<fieldset>
<select id="money" name="money">
<option value="loon">1 dollar</option>
<option value="toon">2 dollar</option>
</select>
<br>
<p id="pg"></p>
</fieldset>
</form>
注意:有2个型号:1)用户2)员工
This page isn’t working 127.0.0.1 is currently unable to handle this request.
HTTP ERROR 500
场景1:输入正确的凭据后,它是正确的
User Table:
email - xxxx@gmail.com
password - 123456
Staff Table:
email - xxxx@gmail.com
password - 123456
但是,如果凭据不正确
方案2:凭据不正确
Login
Email:xxxx@gmail.com
Password:123456
StaffLoginController
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));
}
问题:此错误的原因是什么?