laravel中未显示错误消息

时间:2016-05-27 12:24:48

标签: validation laravel-5.2

我正在使用Laravel 5.2,当我尝试使用错误的用户名和密码组合登录时,我试图显示错误消息,所以当我这样做时,我没有收到错误消息。我不确定我哪里出错了。

我的控制器

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;

class HomeController extends Controller
{
    public function login(Request $request)
    {
        if(Auth::attempt(array('name' => Input::get('name'), 'password' => Input::get('password'))))
        {
            return redirect()->route('dashboard');
        }else{
            return redirect()->route('home')
                ->with('message', 'Your username and password combination is wrong')
                ->withInput();
        }
    }
}

我的index.blade.php

@if ($errors->any())
    {{ implode('', $errors->all('<div>:message</div>')) }}
@endif

<div class="form-wrapper">
    <div class="login-header">
        <h1>Login</h1>
    </div>

    <div class="form_input">
        {{ Form::open(array('url' => 'admin/')) }}
            <div class="form_group">
                {{ Form::label('name', 'Name') }}
                {{ Form::text('name', '' , array("class" => "form-control")) }}
            </div>

            <div class="form_group password-section">
                {{ Form::label('password', 'Password') }}
                {{ Form::password('password', array("class" => "form-control")) }}
            </div>

            <div class="form_group submit_button">
                {{ Form::submit('Submit', array("class" =>"btn btn-info submit", "role" => "button")) }}
            </div>
        {{ Form::close() }}
    </div>
</div>

我的routes.php

Route::group(['middleware' => 'web'], function()
{
    Route::get('admin/', [
        'uses' => 'HomeController@index',
        'as' => 'home'
    ]);

    Route::post('/signin', [
        'uses' => 'HomeController@login',
        'as' => 'Login'
    ]);
});

1 个答案:

答案 0 :(得分:0)

在路线中使用Route :: group(['middleware'=&gt;'auth'],function()