Laravel blade `@auth` condition not working as expected

Posted 2 months ago by amitshahc

I am trying to pick the master blade template dynamically as per the current user roll logged in. (here it should go to the 'shopowner' auth block)

@auth('shopmanager')
@extends('theme::Admins.shopmanager.layout.master')
@endauth

@auth('shopowner')
@extends('theme::Admins.shopowner.layout.master')
@endauth

but this always gives error as it tries to compile the 'shopmanager' master template. It is not going into the 'shopmanager' @auth block because it's not printing anything if I print inside that block.

It only works if I completely comment that line.

P.S.: i tried using this syntax too.. but same results.

if (Auth::guard('shopmanager')->check())
...

also echo the condition check which works perfect without @extends(...) syntax. This goes in shopowner which is right.

@if(Auth::guard('shopmanager')->user())
   {{dd(Auth::guard('shopmanager')->user())}}
@else
   {{dd(Auth::guard('shopowner')->user())}}
@endif

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.