0

I have made a list query that populates my drop down box. I have tried var_dump on the controllers part and it all went well, but whenever I tried to call my function on my blade template, it would return me an error: Undefined variable: categories (View: C:\wamp\www\airlines\app\views\content\onewayflight.blade.php)

What seems to be the problem here?

OnewayflightController.php

   public function onewayflight()
{ 
  $categories = DB::table('oneways')->lists('destination-from');
  return View::make('content.onewayflight')->with('destination-from', $categories);
}

onewayflight.blade.php

{{ Form::select('destination-from', $categories) }}

routes.php

Route::get('flight/onewayflight','OnewayflightController@onewayflight');
1

1 Answer 1

1

You should use in Blade:

{{ Form::select('destination-from', $destination-from) }}

because in your method you used:

with('destination-from', $categories)

so you told that in Blade $categories have to be named $destination-from

However you cannot use - in variable name, so you should probably change it into:

with('destinationFrom', $categories)

and in Blade:

{{ Form::select('destination-from', $destinationFrom) }}
Sign up to request clarification or add additional context in comments.

9 Comments

I bet $destination-from is not a valid variable name. ${'destination-from'} could work tho.
@Jari I know, I added extra explanation to my answer
@MarcinNabiałek Thank you sir! Now, This is clear to me. An added question sir, What if I'd be populating two separate drop down? How can I correctly implement it?
@staphhelpme If you use the same data, you simple create new select using the same data (of course other select name). And if you need more data, you need to pass array in with method
@staphhelpme you need to use ->with(['destination-from'=> $categories, 'other-variable' => $user]); and so on
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.