Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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'));
    }
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Drehmini drehmini Joined 4 Jan 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.