【问题标题】:Error message not showing in laravellaravel 中未显示错误消息
【发布时间】:2016-09-25 19:06:51
【问题描述】:

我正在使用 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>

我的路线.php

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

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

【问题讨论】:

    标签: validation laravel-5.2


    【解决方案1】:

    在路由中使用 Route::group(['middleware' => 'auth'], function()

    【讨论】:

    • 我不知道这将如何工作,因为据我所知Route::group(['middleware'=&gt;'auth'] 仅在您登录后使用。
    • 如果不使用 auth 中间件,那么您将无法在 post 上对用户进行身份验证。
    • 我添加了 Route::group 并得到“页面未正确重定向”
    • 对于 GET 请求还是 POST 请求?
    • 对于 GET 请求
    猜你喜欢
    • 2016-09-29
    • 2017-01-06
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多