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?