samedi 30 septembre 2017

How to pass an array of data from controller to the view using laravel

There are two tables in my database. They are foods and sub_foods. I want to get the names of the sub_foods in Foods model as a array and pass it to the create.blade.php file for make a dynamic dropdown box inside the form. This is my code,

FoodsController.php

public function create()
{
    $sub_foods = ['' => ''] + Sub_food::lists('name','id')->all();
    return view::make('foods.create',array('sub_foods'=>$sub_foods));
}

create.blade.php

 <form action="/foods" method="post">
    
</form>



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2wqrSSP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire