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

问题描述 投票:0回答:1

我想为我的网站制作登录功能。但不幸的是,它提供了未定义的索引:我的AdminController中的电子邮件:

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>
laravel laravel-5.6
1个回答
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');
 }

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

© www.soinside.com 2019 - 2024. All rights reserved.