我的PostController
:
$posts = Post::orderBy('created_at', 'desc')
->where([['status', 'PUBLISHED'],['post_type', 'PORTFOLIO']])
->paginate(9);
$partners = Post::orderBy('created_at', 'desc')
->where([['status', 'PUBLISHED'],['post_type', 'PARTNERS']])
->get();
// return view('landing.onepageindex', ['posts' => $posts], ['pages' => $pages], ['partners' => $partners]);
return view(
'landing.onepageindex',
['posts' => $posts],
['pages' => $pages],
['partners' => $partners]
);
我试图为partners var做foreach,但它说它是未定义的,我在这里做错了什么?我对拉勒维尔很陌生,但这件事让我很困惑。不允许我为同一个帖子创建两个变量(只是不同的帖子类型)?
文章和页面应该正常工作,而合作伙伴却没有。
提前谢谢。
最佳答案
您需要在第二个参数中传递数据以查看
return view(
'landing.onepageindex',
['posts' => $posts, 'pages' => $pages, 'partners' => $partners]
);
关于php - Laravel undefined variable (但已发送),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50566064/