Hello @noblemfd
In the leave_balance() controller method, I think the way the data is fetched (applicable leave, approved leave, etc) makes it difficult for you to show it in the table within your view, because you are essentially gathering columns, not rows of data, for the table.
Perhaps you could try something like the following:
public function leave_balance()
{
...
// Leave Category
$leaveCategories = LeaveCategory::select('leave_category_name')->where('company_id', $userCompany)->get();
// for each leave category, add keys for applicable leave, approved and available
foreach ($leaveCategories as $i) {
$i['applicable_leaves'] = // applicable leaves for this category
$i['approved_leaves'] = // approved leaves for this category
$i['available_leaves'] = // available leaves for this category
}
return view('leave-balances')->with('leaveCategories', $leaveCategories);
Then in your view's table you could
@foreach ($leaveCategories as $i)
<tr>
<td>{{ $i->leave_category_name }}</td>
<td>{{ $i['applicable_leaves'] }}</td>
<td>{{ $i['approved_leaves'] }}</td>
<td>{{ $i['available_leaves'] }}</td>
</tr>
@endforeach
I hope this helps you. It does feel like there's way too much code in the leave_balance() controller method. You might want to consider refactoring the leave balance calculations to their own class.
If there is no field/value for $approvedleaves, it should initialize with 0
It's cleaner to do this in the code where you figure out the value for $i['available_leaves'] and not in the view