79092906

Date: 2024-10-16 07:36:23
Score: 2
Natty:
Report link

but I have not found a way to add a condition.

You can add the condition in you model function firstCheckedChecklistItem() or inside with function itself

public function firstCheckedChecklistItem() { 
    return $this->hasOne('App\Models\CheckedChecklistItem')
         ->whereNotNull('done_by')
         ->latestOfMany(); 
}
  ->with(['machineType.checklistGroup.currentChecklists.checklistItem.firstCheckedChecklistItem' => function($query) {
       $query->whereNotNull('done_by');
  }]) 

Reference: How to access model hasMany Relation with where condition?

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: UnderIdentityCrisis