laravellaravel-5laravel-6laravel-7laravel-views

How to use One view with Multiple Guards Laravel


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

Solution

  • 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