-3

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::select('sub_foods', $sub_foods) }}
</form>
4
  • Search your question's title in stackoverflow : stackoverflow.com/questions/35326115/… Commented Sep 30, 2017 at 13:15
  • see here !! Commented Sep 30, 2017 at 13:23
  • Then I got this error. ErrorException (E_ERROR) Class 'Form' not found (View: C:\xampp\htdocs\Food\resources\views\foods\create.blade.php). How can I import Form class to the blade file. Commented Sep 30, 2017 at 13:58
  • Please reffer this link stackoverflow.com/questions/28753767/… Commented Sep 30, 2017 at 17:34

1 Answer 1

1

Please try this to pass data from controller to view -

public function create()
{
    $sub_foods = Sub_food::all();
    return view('foods.create')->with('sub_foods',$sub_foods);
}

And reffer this link https://laravelcollective.com/docs/5.0/html for ErrorException (E_ERROR) Class 'Form' not found.

Hope this will help you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.