登录页面在laravel 6中通过身份验证重定向到空白页面

时间:2020-03-23 14:38:05

标签: php laravel

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

<?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();
    }

}

loginRequest类

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'],
        ];
    }
}

web.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中更改路由,但是它不起作用。

1 个答案:

答案 0 :(得分:1)

问题是我没有在registerController中正确散列密码,因此无法对登录的用户进行身份验证。