duanjiao6731 2014-03-26 15:51
浏览 33
已采纳

Laravel 4 Auth错误的用户名或电子邮件错误

i want to give the user a visual feedback if they entered wrong login information.

public function doLogin()
{
  $rules = array(
    'email'    => 'required|email',
    'password' => 'required|min:3'
  );

  $validator = Validator::make(Input::all(), $rules);

  if ($validator->fails()) {
    return Redirect::route('login')
      ->withErrors($validator)
      ->withInput(Input::except('password'));
  } else {
    $userdata = array(
      'email' => Input::get('email'),
      'password' => Input::get('password')
    );

    if (Auth::attempt($userdata)) {
      return Redirect::route('dashhome')
        ->withJsd('true');
    } else {
      return Redirect::route('login')
        ->withErrors(['wrongpw','Wrong E-mail address or Password']);
    }

  }
}

and on my login view i have this code

@if ($errors->has('wrongpw'))
  <script>
    $.gritter.add({
      title: 'Ups!',
      text: "{{ $errors->first('wrongpw') }}",
      class_name: 'warning',
      time: ''
    });
  </script>
@endif

But that doesn't work. Any idea what i make wrong or any suggestions on how to do it better?

Thanks

  • 写回答

1条回答 默认 最新

  • dongzilu0178 2014-03-26 16:26
    关注

    i think you are not passing errors in a correct associative array,

    try

    ->withErrors(array('wrongpw' => 'Wrong E-mail address or Password'));
    

    or

    ->withErrors(['wrongpw' => 'Wrong E-mail address or Password']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入