未定义索引:Laravel 5.6中的电子邮件错误

时间:2018-09-06 10:53:39

标签: laravel laravel-5.6

我想为我的网站设置登录功能。但不幸的是,它在我的AdminController中给出了未定义的Index:email:

public function login(Request $request)
{
        if($request->isMethod('post'))
        {
            $data = $request->input();
            if (Auth::attempt(['email' => $data['email'], 'password' => $data['password'],'admin' => '1'])) {
                echo "Success";
                //console.log("Successfull");
                die;
            }
            else
            {
                echo "Failed";
                //console.log("Failed");
                die;
            }
        }
        return view('admin.admin_login');
 }

刀片中:

<div class="input-group mb-3">
    <div class="input-group-prepend">
        <span class="input-group-text bg-success text-white" id="basic-addon1"><i class="ti-user"></i></span>
    </div>
    <input type="email" name="email" class="form-control form-control-lg" placeholder="Email" aria-label="Email" aria-describedby="basic-addon1" required="">
 </div>

1 个答案:

答案 0 :(得分:0)

$data['email']更改为$request->email。因为$ request包含对象而不是数组

您可以执行以下操作

public function login(Request $request)
{
        if($request->isMethod('post'))
        {

            if (Auth::attempt(['email' =>$request->email, 'password' => $request->password,'admin' => '1'])) {
                echo "Success";
                //console.log("Successfull");
                die;
            }
            else
            {
                echo "Failed";
                //console.log("Failed");
                die;
            }
        }
        return view('admin.admin_login');
 }

即使我在刀片模板中也看不到密码字段