1

i kept getting the same error,

undefined variable: theaters on my blade, line 14.

here is my addcine.blade.php line 14

@foreach ($theaters as $theater)
    <option value="{{ $theater->name }}"/>
    @endforeach

here is my addcinemacontroller

public function index(){

$theaters = Theater::all();

return view('schedules.addcine', compact('name'));

and my route

Route::get('addcinema','AddCinemaController@index');
});
1
  • return view('schedules.addcine', compact('theaters')); Commented Jul 20, 2017 at 9:48

4 Answers 4

5

It should be:

return view('schedules.addcine', compact('theaters'));

compact('theaters') does exactly this:

return view('schedules.addcine', ['theaters' => $theaters]);
Sign up to request clarification or add additional context in comments.

1 Comment

oh. thank you very much. such a silly mistake. forgive my ignorance
2
return view('schedules.addcine', compact('theaters'));

you are not sending the $theaters value to the view,

Comments

1

You are sending name instead of theaters in controller

public function index(){

$theaters = Theater::all();

return view('schedules.addcine', compact('theaters'));

Comments

0

You need to return the $thaters variable to view so that you can use it there.

Return like this:

return view('schedules.addcine', compact('theaters'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.