@extends('admin/layouts/default') {{-- Page title --}} @section('title') Maintenance Requests List @parent @stop {{-- Page content --}} @section('content') Assign Expert Dashboard Maintenance Requests Maintenance Requests Assign Expert {!! Form::label('cat_id', 'Expert: ') !!} @php // Example: join role_users -> dmuemployee2s $experts = DB::table('role_users') ->join('dmuemployee2s', 'role_users.email', '=', 'dmuemployee2s.email') ->where('role_users.role_id', 42) ->select( 'dmuemployee2s.firstname as firstname', 'dmuemployee2s.lastname as lastname', 'dmuemployee2s.email as email' ) ->get(); @endphp Select Expert: Select Expert @foreach($experts as $expert) @php // Check if 'email' exists first to avoid null errors $email = $expert->email ?? null; echo $email; // Count assigned tasks based on email $taskCount = 0; if ($email) { $taskCount = DB::table('staffrequests') ->where('assignedexpert', $email) ->count(); } @endphp @if($email) {{ $expert->firstname }} {{ $expert->lastname }} ({{ $taskCount }}) @endif @endforeach Message: @lang('Assign Experts') @stop {{-- Footer scripts --}} @section('footer_scripts') @stop