You have too many queries to get the vehicles and images. In the vehicles case, you can reduce them to 1 for each Inventory
record by eager-loading the relationship:
$tmp = Inventory::with('vehicle')
where(
'dealer_id', '=', $dealer_id
)->where(
'inventories.is_sold', '=', 0
)->where(
'is_active','=', 1
);
If the image is a relationship on Inventory
you can add it to the with
method call, if not you can collect the image search parameters separately and then perform a single select