Category: Laravel, PHP

So let’s talk in a high-level language, “an asset has many calibrations and the valid calibration is only the most recent one”. If one wants to do a select query for every asset that has a good calibration status where that constraint is present, that person would need to select based on the latest row of calibrations data. Laravel has provided its users with a method to do such a specifics job and that is whereHas.

The query would return the asset with the id of 1 although the last calibration is done with a status of zero and render the query to be invalid.

The solution is to use the query builder join while only selecting the fields from the assets table and combining it with a subquery to match the calibration id with the latest calibration id that corresponds to the asset in the relation.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners