php 未定义的变量$follows overtrue/laravel-follow

ldioqlga  于 2022-12-21  发布在  PHP
关注(0)|答案(1)|浏览(111)

我得到这个错误,但是使用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"
u0sqgete

u0sqgete1#

像这样使用compact()

return view('/@', compact('user', 'posts', 'followings'));

或者使用with()

return view('/@')->with(['user' => $user, 'posts' => $posts, 'followings' => $followings]);

相关问题