我想问。我使用foreach来显示数据库中的数据。但是看不到任何东西。这是我的代码:
public function page($page_url = null){
if($page_url == "villas"){
$villa = Pages::where(['url_page' => $page_url])->first();
$postvilla = Posts::where(['id_page' => $villa->id_page]);
return view('front.villa', compact(array('villa', 'postvilla')));
}else if($page_url == "admin"){
return redirect('/admin/home');
}
}
答案 0 :(得分:0)
您可以像这样紧凑地传递变量
return view('front.villa', compact('villa', 'postvilla'));