0
votes

I want to ask. I use foreach for showing my data from database. But nothing happen on view. Here is my code :

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');
    }
}
1

1 Answers

0
votes

You can pass variables in compact like

return view('front.villa', compact('villa', 'postvilla'));