Just an update.
I've fixed this problem by filtering the returned Equipment collection
public function index()
{
$equipment = Equipment::with('transactions')->get();
$overdue = $equipment->filter(function($item) {
$lastTransaction = $item->transactions->last();
if(!is_null($lastTransaction) &&
!is_null($lastTransaction->due_date) &&
$lastTransaction->due_date->lt(Carbon::today())
) {
return true;
}
});
return view('inventory.index', compact('equipment', 'overdue'));
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community