在 laravel 6 中进行身份验证后登录页面重定向到空白页面

我的登录页面将我重定向到带有 url:http://127.0.0.1:8000/login而不是仪表板的空白页面。这是我的登录控制器


<?php


namespace App\Http\Controllers;


use Illuminate\Http\Request;

use Illuminate\Support\Facades\Auth;

use Illuminate\Support\Facades\Session;

use App\Http\Requests\LoginRequest;


class LoginController extends Controller

{

    public function show()

    {

        return view('auth/login');

    }


    public function authenticate(LoginRequest $requestFields)

    {


        $attributes = $requestFields->only(['username', 'password']);


        if (Auth::attempt($attributes)) {


            return redirect()->route('dashboard');


        }

    }


    public function logout()

    {

        Session::flush();

        Auth::logout();

        return back();

    }


}

登录请求类


class LoginRequest extends FormRequest

{

    /**

     * Determine if the user is authorized to make this request.

     *

     * @return bool

     */


    public function authorize()

    {

        return true;  // Set this to "true" else Unauthorized error will be thrown

    }


    public function rules()

    {

        return [

            'username'     => ['required', 'string'],

            'password'  => ['required', 'string', 'min:8'],

        ];

    }

}

网站.php


// Register & Login User

Route::post('/login', 'LoginController@authenticate');

Route::post('/register', 'RegistrationController@register');



// Protected Routes - allows only logged in users

Route::middleware('auth')->group(function () {

    Route::get('/dashboard', 'DashboardController@index')->name('dashboard');

    Route::post('/logout', 'LoginController@logout');

});

我希望在使用用户名和密码登录后重定向到仪表板页面,我尝试更改 RedirectIfAuthenticated.php 中的路由,但没有成功。


红颜莎娜
浏览 157回答 1
1回答

泛舟湖上清波郎朗

问题是我没有在 registerController 中正确地散列我的密码,因此我无法验证登录的用户。
打开App,查看更多内容
随时随地看视频慕课网APP