Laravel 登录表单 - 电子邮件不正确

当我尝试在 Laravel 中使用表单登录并保存会话以在主页中重定向时,我总是收到消息说所需的电子邮件不正确,即使它是正确的


这是控制器:


public function welcome (Request $request) {

    { 

        $this->validate($request, [


        'mail' => 'required|email',

        'mdp'=> 'required'

    ]);

    $patt= patient::orderBy('created_at','desc')->get() ;

    foreach ($patt as $log ) 

    {

        if (( $log->Login== $request->input('mail') ) && ( $log->Password== $request->input('mdp') ))

        {

            $request->session()->put('log_in', true);

            return redirect('index' , ['helloo'=>$log]);

        }


     return back()->withErrors([

        'message'=> 'Emails or password not correct!'

        ]) ;  }


}

网站.php:


Route::Post('/index' , 'patientcontroller@welcome')->name('rahmaa');

形式:


<form  class="form-signin" method="post" action="{{route('rahmaa')}}"> 

    @csrf  

  <input type="text" class="form-control" name="email" placeholder="Adresse mail" data-rule="email" autofocus="" /> </br>

      <input type="password" class="form-control" name="mdp" placeholder="Mot de passe" data-rule="required"/>      


      <button class="btn btn-primary btn-block" type="submit"> Se connecter </button> <br>

     <center> <a href="inscription"> Inscrivez-vous </a>  </center> 

    </form>


慕丝7291255
浏览 118回答 2
2回答

慕标5832272

您收到错误邮件的原因是必需的,因为您发送的是电子邮件而不是邮件。只是mail改成email$this->validate($request, [&nbsp; &nbsp; 'email' => 'required|email',&nbsp; &nbsp; 'mdp'=> 'required']);或将输入更改name attribute为mail<input name="mail"/>重写你的功能use Illuminate\Support\Facades\Hash;....public function welcome(Request $request)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $request->validate([&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'email' => 'required|email',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'mdp' => 'required',&nbsp; &nbsp; &nbsp; &nbsp; ]);&nbsp; &nbsp; &nbsp; &nbsp; // since email is unique. no need to grab all data&nbsp; &nbsp; &nbsp; &nbsp; $patient = patient::where('Login', $request->input('email'))->first();&nbsp; &nbsp; &nbsp; &nbsp; // if patient exists&nbsp; &nbsp; &nbsp; &nbsp; if ($patient) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // check hashed password&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // assuming $patient->Password hashed&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Hash::check($request->input('mdp'), $patient->Password)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $request->session()->put('log_in', true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return redirect('index', compact('patient'));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return back()->withErrors([&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'message' => 'Emails or password not correct!',&nbsp; &nbsp; &nbsp; &nbsp; ]);&nbsp; &nbsp; }

三国纷争

你的 HTML 是<input type="text" class="form-control" name="email" />&nbsp;输入的名称是“电子邮件”,在你正在搜索“邮件”的 php 中'mail'&nbsp;=>&nbsp;'required|email',它应该是:<input&nbsp;type="text"&nbsp;class="form-control"&nbsp;name="mail"&nbsp;/>
打开App,查看更多内容
随时随地看视频慕课网APP