亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

登錄后重定向 laravel 7 給我白頁,沒有錯誤

登錄后重定向 laravel 7 給我白頁,沒有錯誤

PHP
鳳凰求蠱 2023-07-30 11:13:45
我正在使用 Laravel 7。我在 LoginController 中定制了登錄方法,檢查您輸入的是“申請人”還是“業務”并重定向到不同的路線,應該是非?;镜摹,F在登錄后,它給我空白的白頁,Laravel 日志或 laravel 開發服務器上沒有錯誤。protected function login(Request $request){    $credentials = $request->only('email', 'password');    if (Auth::attempt($credentials)) {        $user = Auth::user();        if (Auth::check()) {            if ($user->userType === 'Applicant') {                return redirect()->route('home');            }            if ($user->userType === 'Business') {                return redirect()->route('dashboard');            }        }    }}這段代碼有什么問題?網頁.php:Route::get('login', 'Auth\LoginController@showLoginForm')->name('auth.login');Route::post('login', 'Auth\LoginController@login')->name('login');Route::get('/home', 'HomeController@index')->name('home');Route::get('/dashboard', 'HomeController@dashboard')->name('dashboard');家庭控制器public function __construct(){    $this->middleware('auth');}public function index(){    return view('home');}public function dashboard(){    return view('dashboard');}---- 添加了 Home.blade.php ----@extends('layouts.app')@section('content')<div id="app" class="ml-1 mr-1 border border-dark">      <dashboard v-bind:u-Id="{{ Auth::user()->id }}"        v-bind:p-Id="{{ auth()->user()->profile()->first()->id }}"        > </dashboard></div>@endsection
查看完整描述

2 回答

?
白豬掌柜的

TA貢獻1893條經驗 獲得超10個贊

我建議不要為此覆蓋登錄方法。相反,我建議使用經過身份驗證的“hook”:


protected function authenticated(Request $request, $user)

{

? ? if ($user->userType === 'Applicant') {

? ? ? ? return redirect()->route('home');

? ? }


? ? if ($user->userType === 'Business') {

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

? ? }

}


查看完整回答
反對 回復 2023-07-30
?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

有一個默認的重定向頁面更符合邏輯,例如home. 我認為下面的代碼更明智。


protected function login(Request $request){

    $credentials = $request->only('email', 'password');


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


        $user = Auth::user();


        if (Auth::check()) {


            if ($user->userType === 'Business') {

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


            } else {

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

            }

        }

    }

}

如果您想要另一個默認重定向頁面,請elseif在部分中使用并添加您的默認頁面else。


查看完整回答
反對 回復 2023-07-30
  • 2 回答
  • 0 關注
  • 190 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號