0
데이터에서 관계를 가져 오려고합니다. 사용자 폴더에서Laravel에서 관련 데이터에 액세스하기가 낯설기
public function folders()
{
return $this->hasMany("App\Folder");
}
public function rootFolder()
{
return $this->folders()->where("parentid", null);
}
에서
는
$root = auth()->user()->rootFolder;
$subs = $root->subFolders;
foreach ($subs as $sub) {
echo $sub->name;
}
나는
Property [subFolders] does not exist on this collection instance.
0 컨트롤러에서
public function subFolders() {
return $this->hasMany("App\Folder", "parentid");
}
public function parentFolder()
{
return $this->belongsTo("App\Folder", "parentid");
}
얻고있다 그러나 if
$root = new Folder;
예외가 사라집니다.
어떻게 든 rootFolder 함수의 반환 데이터를 폴더라고 말해야합니까?
$root = auth()->user()->rootFolder;
$subs = $root->subFolders;
이
이 변경 폴더 개체를 반환 작동합니다 : 그래서 하나는 쿼리의 속성을 "하위 폴더"에 접근을 시도
public function rootFolder()
{
return $this->folders()->where("parentid", null);
}
: