Laravel 5.3 验证错误的空白页

Laravel 5.3 blank page with wrong authentication

我有一个用于登录我的用户的页面。该页面非常简单。当我尝试使用正确的 username/password 时,它 returns 我看到了我想要的视图,但是在无效的组合上,我落在了一个空白的白页上。如有任何帮助,我们将不胜感激。

login.blade.php:

<form action="{{ route('submitlogin') }}" method="post">
    <div class="form-group has-feedback {{ $errors->has('username') ? 'has-error' : '' }}">
        @if($errors->has('username'))
            <label class="control-label" for="username"><i class="fa fa-times-circle-o"></i> {{ $errors->first('username') }}</label>
        @endif
        <input type="text" class="form-control" placeholder="Username" id="username" name="username" value="{{ Request::old('username') }}">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
    </div>
    <div class="form-group has-feedback {{ $errors->has('password') ? 'has-error' : '' }}">
        @if($errors->has('password'))
            <label class="control-label" for="password"><i class="fa fa-times-circle-o"></i> {{ $errors->first('password') }}</label>
        @endif
        <input type="password" class="form-control" placeholder="Password" id="password" name="password" >
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
    </div>
    <div class="row">
        <div class="col-xs-4">
            <button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
            <input type="hidden" value="{{ Session::token() }}" name="_token" />
        </div>
    </div>
</form>

web.php(路线):

Route::post('/home', [
            'uses' => 'SigninSignupController@postSubmitLogin',
            'as' => 'submitlogin'
    ]);

SigninSignupController.php:

public function postSubmitLogin(Request $request)
    {
        $this->validate($request, [
                'username' => 'required|alpha|max:20|min:4',
                'password' => 'required|max:20|min:7'
        ]);

        if (Auth::attempt(['username' => $request['username'], 'password' => $request['password']])) {
            return view('pages.welcome');
        }
    }

有什么问题吗?

您需要在 if (Auth::attempt) 行中添加 else。 像这样:

if (Auth::attempt(['username' => $request['username'], 'password' => $request['password']])) {
    return view('pages.welcome');
} else {
    // user is not valid, redirect back to login here
    session()->flash('alert', 'Bad Credentials');
    return view('pages.login');
}