登录后重定向不工作但注册后工作正常

时间:2017-02-02 12:50:07

标签: laravel laravel-5.3

我使用了php artisan make:auth。我正在将电子邮件更改为用户名以进行登录。 在login.blade.php中,我刚用username替换了电子邮件。

<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
                            <label for="username" class="col-md-4 control-label">Username</label>

                            <div class="col-md-6">
                                <input id="username" type="name" class="form-control" name="username" value="{{ old('username') }}" required autofocus>

                                @if ($errors->has('username'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('username') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

现在,我没有收到错误信用的错误消息,也没有重定向到/home以获得正确的信用,登录页面只是重新加载。 我还在RegisterController中的create function中添加了这个'username' => $data['username'],,它在注册后成功重定向到/ home,但是在登录时没有。

我还在logincontroller中覆盖了这个属性:protected $username = 'username';

2 个答案:

答案 0 :(得分:2)

您是否覆盖以下功能?

public function username()

位于:vendor / laravel / framework / src / Illuminate / Foundation / Auth / AuthenticatesUsers.php。

变化:

public function username()
{
        return 'email';
}

要:

public function username()
{
        return 'username';
}

还要确保在数据库中添加了用户名字段。

您的LoginController应如下所示:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    public function username()
{
    return 'username';
}

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';


    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }

}

答案 1 :(得分:1)

在Laravel 5.3中,您可以覆盖<div class="bar bar-header item-input-inset bg-white" ng-if="showSearchBox"> <label class="item-input-wrapper"> <i class="icon ion-ios-search placeholder-icon"></i> <input type="search" placeholder="Search" ng-model="searchText"> </label> <button class="button button-icon icon ion-ios-close-empty" ng-click="toggleSearchBox()"></button> </div> <div class="list"> <a class="item item-icon-right" ng-repeat="(id, profession) in professionList | filter:searchText" ui-sref="app.search-people({'professionId': profession.id})">{{profession.name}}<i class="icon ion-ios-arrow-right"></i></a> </div> 中的sendLoginResponse()方法,例如:

LoginController.php