我得到这个错误,但是使用dd($follow);在家庭控制器中,显示日期,但当我试图foreach视图时,我得到这个错误。
有人知道我做错了什么吗
未定义的变量$following
主控制器
public function userFollow($username)
{
$user = User::where('username', $username)->firstOrFail();
$posts = Post::where('user_id', $user->id)->simplePaginate(3);
$user = User::find($user->id);
$followings = $user->followings()->with('followable')->get();
dd($followings);
return view('/@', compact('user'), compact('posts'), compact('followings'));
}
在.blade.php上查看
@foreach($followings as $following)
{{$following->id}}
@endforeach
日(美元以下);回返者
#attributes: array:7 [▼
"id" => 60
"user_id" => 5
"followable_type" => "App\Models\User"
"followable_id" => 9
"accepted_at" => "2022-12-20 20:36:49"
"created_at" => "2022-12-20 20:36:49"
"updated_at" => "2022-12-20 20:36:49"
1条答案
按热度按时间u0sqgete1#
像这样使用
compact()
或者使用
with()