@extends('layouts.app') @section('content')

Users

{{-- Show Add User based on role: super/co/branch_admin --}} @if(in_array(auth()->user()->role, ['super_admin'])) Add User @endif
@if (session('success'))
{{ session('success') }}
@endif
@forelse ($users as $user) @empty @endforelse
# Name Email Role Branch Actions
{{ $user->id }} {{ $user->name }} {{ $user->email }} {{ str_replace('_', ' ', $user->role) }} @if(in_array($user->role, ['super_admin', 'co_admin'])) N/A @else {{ $user->branch?->name ?? 'N/A' }} @endif {{-- Inline logic for Edit: Super admin always, co_admin if not super_admin, branch_admin if same branch and role branch_admin/staff --}} @if(auth()->user()->role === 'super_admin' || (auth()->user()->role === 'co_admin' && $user->role !== 'super_admin') || (auth()->user()->role === 'branch_admin' && in_array($user->role, ['branch_admin', 'staff']) && $user->branch_id === auth()->user()->branch_id)) Edit @else No edit @endif {{-- Inline logic for Delete: Super admin if not self, co_admin never, branch_admin if staff in same branch and not self --}} @if((auth()->user()->role === 'super_admin' && $user->id !== auth()->user()->id) || (auth()->user()->role === 'branch_admin' && $user->role === 'staff' && $user->branch_id === auth()->user()->branch_id && $user->id !== auth()->user()->id))
@csrf @method('DELETE')
@else No delete @endif
No users found.
{{ $users->links() }}
@endsection