0
Ich versuche, Beziehungen von Daten zurückgegeben.Eloquent Zugriff auf verwandte Daten in Laravel
in Benutzer
public function folders()
{
return $this->hasMany("App\Folder");
}
public function rootFolder()
{
return $this->folders()->where("parentid", null);
}
in Ordner
public function subFolders() {
return $this->hasMany("App\Folder", "parentid");
}
public function parentFolder()
{
return $this->belongsTo("App\Folder", "parentid");
}
in Controller-
$root = auth()->user()->rootFolder;
$subs = $root->subFolders;
foreach ($subs as $sub) {
echo $sub->name;
}
Ich erhalte
Property [subFolders] does not exist on this collection instance.
Wenn jedoch
$root = new Folder;
Ausnahme verschwindet.
Muss ich irgendwie die Rückgabedaten von der rootFolder-Funktion sagen, dass Sie ein Ordner sind?