dongnao9525 2018-02-16 05:40
浏览 107
已采纳

Laravel - 如果登录凭据错误,则在同一页面上显示错误

I am new to Laravel and i am working on login page in which i want throw error below input tags if login credentials are wrong. I have written some code and everything is working fine but errors are not showing.

Have a look at what I have done.

In Controller:

public function login(Request $req) {

    $email = $req->input('email');

    $password = $req->input('password');

    $checkLogin = DB::table('admin')->where(['email'=>$email,'password'=>$password])->get();

    if(count($checkLogin) > 0) {
        echo "Login Successfull";
    }
    else {
        // echo "Login Failed!";
        return Redirect::route('admin-login')->with();
    }
}

In View:

<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>

@if ($errors->has('email'))

<span class="help-block">

<strong>{{ $errors->first('email') }}</strong>

</span>

@endif

In Route:

Route::post('admin-login-result','AdminLoginController@login')->name('admin-log');

Thanks

  • 写回答

2条回答 默认 最新

  • duanliaozhi2915 2018-02-16 05:50
    关注

    Try this one in your else block

    Redirect::back()->withErrors(['msg', 'The Message']);
    

    In view file use like this

    @if($errors->any())
      <h4>{{$errors->first()}}</h4>
    @endif
    

    Refer this link for more details https://itsolutionstuff.com/post/laravel-53-form-input-validation-rules-example-with-demoexample.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 asp.textbox后台赋值前端不能显示什么原因
  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误