0

I have multiple guards in my system

Admin
User

Admin and User both can add the Organizations details but they have different template layout. What i'm doing now i create views of each guard like this

views
  user
    organizations
       index.blade.php
       _form.blade.php
       create.blade.php
       edit.blade.php
  admin
    organizations
       index.blade.php
       _form.blade.php
       create.blade.php
       edit.blade.php

Now i want to create one views which can be used by multiple guards with different layouts

views
   organizations
      index.blade.php
      _form.blade.php
      create.blade.php
      edit.blade.php
antweny
  • 67
  • 2
  • 10
  • I don’t know if I understand you correctly, but are you trying to have a view that displays different information depending on whether the user has a user role or an admin role? – Savlon Apr 15 '20 at 22:31
  • Yes one view displays same information but different template based on the guards not roles – antweny Apr 15 '20 at 22:43

1 Answers1

1

From the Laravel Blade Documentation:

If needed, you may specify the authentication guard that should be checked when using the @auth and @guest directives:

@auth('admin')
    // The user is authenticated...
@endauth

@guest('admin')
    // The user is not authenticated...
@endguest
mchljams
  • 441
  • 2
  • 9
  • current i'm doing this but i'm worried about the performance of checking current user logged guard every time visit the page. Is there another way of doing this? – antweny Apr 16 '20 at 11:51
  • If that is what you are doing, then I'd say you are good. This should not be impacting performance. – mchljams Apr 16 '20 at 14:10