I have a many to many relation in Partners model that is referencing itself. The pivot table partner_owners has owner_id, owned_id, percent
So a partner can own another partner and so on.
How can I query all the nested relations for a partner without knowing how many levels are there?
For example $partner = Partner::where('id', 1)->get(); if this partner is owned by two others and each of the two others are owned by some others and so on I can't figure out a way to display them all without knowing how many levels are there.
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Partners extends Model
{
/**
* Owners of the partner.
*/
public function Owners()
{
return $this->belongsToMany(Partner::class, 'partner_owners', 'owned_id', 'owner_id')
}
}