Nov 10, 2021
0
Level 10
Access a model method collection from a Nova Resource, and display the result collection as a table in Laravel Nova
Hi devs,
I have a method in my model that represents a filtered collection of a sibling tree.
public function siblings()
{
if (is_null($this->father_id) && is_null($this->mother_id)) {
return collect([]);
}
return User::where('id', '!=', $this->id)
->where(function ($query) {
if (!is_null($this->father_id)) {
$query->where('father_id', $this->father_id);
}
if (!is_null($this->mother_id)) {
$query->orWhere('mother_id', $this->mother_id);
}
})
->orderBy('date_of_birth')->get();
}
I want to access the above model method siblings() in the Nova User show view method as a collection in a table.
Please or to participate in this conversation.