Laravel 5.3 auth:user():以guest身份而不是user身份登录 [英] Laravel 5.3 auth:user(): logged in as guest instead of user

查看:112
本文介绍了Laravel 5.3 auth:user():以guest身份而不是user身份登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用laravel 5.3,并使用Hesto / multi-auth软件包。我的home.blade工作正常,在我的导航栏中它返回当前的登录用户。但每次我创建一个新视图,并将我的导航栏扩展到它我的导航栏显示登录注册而不是用户名,即使我已经登录。



所以,当我在home.blade时,我成功以用户身份登录,但当我导航到另一个视图时,我被读作客人。作为样本,我试验了我的welcome.blade。



这是我的一个用户的路线。



I'm using laravel 5.3, and using Hesto/multi-auth package. All my home.blade is working fine, in my nav bar it returns the current login user. But everytime I created a new view, and extend my nav bar to it my nav bar shows "LOGIN REGISTER" instead of username even though I'm already logged in.

So, when I'm in home.blade I successfully logged in as a user, but when I navigate to another view, I am read as a guest. As a sample, I experimenting my welcome.blade.

This is my route for one of my user.

Route::group(['prefix' => 'customer', 'middleware' => 'customer'], function () {


Route::model( 'customer' , 'App\Customer' );
  Route::get('/login', 'CustomerAuth\LoginController@showLoginForm');
  Route::post('/login', 'CustomerAuth\LoginController@login');
  Route::post('/logout', 'CustomerAuth\LoginController@logout');

    Route::get('registration_form', function()
    {
        return view('customer/auth/registration_form');
    });
    Route::post("register_customer", 'CustomerAuth\RegisterController@register');

  Route::post('/password/email', 

'CustomerAuth\ForgotPasswordController@sendResetLinkEmail');
      Route::post('/password/reset', 'CustomerAuth\ResetPasswordController@reset');
      Route::get('/password/reset', 'CustomerAuth\ForgotPasswordController@showLinkRequestForm');
      Route::get('/password/reset/{token}', 'CustomerAuth\ResetPasswordController@showResetForm');
    });





Kernel.php





Kernel.php

protected $routeMiddleware = [
       'business' => \App\Http\Middleware\RedirectIfNotBusiness::class,
       'business.guest' => \App\Http\Middleware\RedirectIfBusiness::class,
       'customer' => \App\Http\Middleware\RedirectIfNotCustomer::class,
       'customer.guest' => \App\Http\Middleware\RedirectIfCustomer::class,
       'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
       'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
       'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
       'can' => \Illuminate\Auth\Middleware\Authorize::class,
       'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
       'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
   ];





我的尝试:



我尝试将导航栏扩展到我的welcome.blade



What I have tried:

I tried extending navbar to my welcome.blade

推荐答案

routeMiddleware = [
'business'=> \ App\Http\Middleware \ RededIfNotBusiness :: class,
'business.guest'=> \ App\Http\Middleware \ RededIfBusiness :: class,
'customer'=> \ App\Http\Middleware \ RededIfNotCustomer :: class,
'customer.guest'=> \ App\Http\Middleware \ RededIfCustomer :: class,
'auth'=> \ Illuminate\Auth\Middleware \Authenticate :: class,
'auth.basic'=> \ Illuminate\Auth\Middleware \ AututnticateWithBasicAuth :: class,
'bindings'=> \ Illuminate\Routing \ Middleware \ SubststituteBindings :: class,
'can'=> \ Illuminate\Auth\Middleware \授权:: class,
'client'=> \ App\Http\Middleware \ RedirectIfAuthenticated :: class,
'throttle'=> \ Illuminate\Routing\Middleware \ThrottleRequests :: class,
];
routeMiddleware = [ 'business' => \App\Http\Middleware\RedirectIfNotBusiness::class, 'business.guest' => \App\Http\Middleware\RedirectIfBusiness::class, 'customer' => \App\Http\Middleware\RedirectIfNotCustomer::class, 'customer.guest' => \App\Http\Middleware\RedirectIfCustomer::class, 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, ];





我的尝试:



我尝试将导航栏扩展到我的welcome.blade



What I have tried:

I tried extending navbar to my welcome.blade


这篇关于Laravel 5.3 auth:user():以guest身份而不是user身份登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆