这是我第一次在laravel上登录。我按照这里的步骤进行了操作:https://scotch.io/tutorials/simple-and-easy-laravel-login-authentication。 但是这个错误出现了:
我真的很困惑这个错误是什么,因为我是laravel的新手? 这是我的控制器代码:
public function login()
{
$admins = Admin::all();
$validator = \Validator::make($admins , ['username' => 'required', 'password' => 'required']);
if ($validator->passes())
{
$userdata = array(
'username' => Admin::get('username'),
'password' => Admin::get('password'));
if (Auth::attempt($userdata))
{
echo 'Success';
}
else {
return Redirect::to('login');
}
}
}
这是我的路线:
Route::resource('Admins','AdminController');
Route::post('login', array('uses' => 'AdminController@login'));
答案 0 :(得分:-1)
这是问题,
$admins = Admin::all();
$validator = \Validator::make($admins , ['username' => 'required', 'password' => 'required']);
将其替换为:
$inputs = Input::all();
$validator = \Validator::make($inputs , ['username' => 'required', 'password' => 'required']);
并且不要忘记改变:感谢FatBoyXPC
$userdata = array(
'username' => Admin::get('username'),
'password' => Admin::get('password'));
with:
$userdata = array(
'username' => Input::get('username'),
'password' => Input::get('password'));