-1

I have a view where I want to display some content according to the adminRole column in the admin table.

My controller

public function adminNotificationList(){
  $admin= Admin::all();
  return view('Notification.notification_admin', compact('admin'));
}

My view

@foreach ($admin as $role)
    {{$role->adminRole}}
@endforeach

When I do this, I get the correct roll listed for all the admins. However what I want to do is display a table if the role is 1 else display another table something like

@foreach ($admin as $role)
   @if ($role->adminRole == 1)
    show something
   @elseif ($role->adminRole == 2)
    show something
   @endelseif
   @endif
@endforeach

But I am not being able to do it as i think it is not the correct way to do it.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mill3r
  • 544
  • 1
  • 10
  • 31

1 Answers1

-1

controller

public function adminNotificationList(){

            $admin = [];
            $admin['admins']= Admin::where('id', Auth::user()->id)->get();

            //dd($admin);
            return view('Notification.notification_admin', compact('admin'));

    }

view

@foreach ($admin['admins'] as $admin)

@endforeach

@if ($admin->adminRole == 1)
    enter stuff here......
@endif

this way it will pass the id of the logged in admin and thus you can check any column from the admin table with if else to restrict blade content according to who is logged in.

Mill3r
  • 544
  • 1
  • 10
  • 31