How to check in a Vue component if a user is authenticated in Laravel?

前端 未结 4 1729
醉酒成梦
醉酒成梦 2021-02-04 07:49

As the title states, I\'m a little confused how I would tackle a method in my Vue Component with if/else statement based on if the user is logged in and authenticated with Larav

4条回答
  •  清酒与你
    2021-02-04 08:40

    Putting a script within blade file will throw Vue Warning. Let me answer "How to check in a Vue component if a user is authenticated in Laravel" and leave you with your Vuex complexity. Also this method is simpler.

    So, in your controller:

    public function index()
    {
        return view('index')->with('auth_user',  auth()->user());
    }
    

    In your blade(main.blade.php):

    In your vue-component, get your props(ExampleComponent.vue):

    
    

    Returns null if user is not logged in

提交回复
热议问题