zurückkehren Wie kann ich alle IDs von AllSubSections
(alle Ebenen) RückLaravel alle IDs von Nachkommen
class Section extends Model
{
public function Ads()
{
return $this->hasMany(Ad::class);
}
public function AllSubSections()
{
return $this->SubSections()->with('AllSubSections');
}
public function SubSections()
{
return $this->hasMany(Section::class);
}
public function Parent()
{
return $this->belongsTo(Section::class);
}
}
was derzeit tue, ist:
$section = Section::where('name', 'Properties')->first();
$subSections = $section->AllSubSections;
$subSections->pluck('id')
aber es gibt nur die erste Ebene nicht alle Ebenen.
'$ section = Abschnitt :: where ('name', 'Eigenschaften') -> get() -> first();' Warum? '$ section = Section :: where ('name', 'Properties') -> first();' Benutze stattdessen –
@RajenderJoshi, ich testete, vermisste es herum und vergaß es zu ändern. – Abanoub