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');
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
staphhelpme
  • 55
  • 2
  • 13
  • 1
    similar question : [**`how-to-pass-data-to-view-in-laravel`**](http://stackoverflow.com/questions/18341792/how-to-pass-data-to-view-in-laravel) – Mithun Satheesh Oct 03 '14 at 11:03

1 Answers1

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) }}
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • I bet `$destination-from` is not a valid variable name. `${'destination-from'}` could work tho. – sybear Oct 03 '14 at 11:03
  • 1
    @Jari I know, I added extra explanation to my answer – Marcin Nabiałek Oct 03 '14 at 11:04
  • @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 Oct 03 '14 at 11:50
  • 1
    @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 – Marcin Nabiałek Oct 03 '14 at 11:53
  • I'd be getting different content from different column but place it on the same blade template.. I have tried copying the working code and change the necessary details but it would give me unidentified variable.. – staphhelpme Oct 03 '14 at 11:59
  • 1
    @staphhelpme you need to use `->with(['destination-from'=> $categories, 'other-variable' => $user]);` and so on – Marcin Nabiałek Oct 03 '14 at 12:01
  • @MarcinNabiałek Yes! Thank you so much sir! One last thing, would it be possible to filter the results because in my db entries, I've got repeating content. If so, can you give me an idea? – staphhelpme Oct 03 '14 at 12:08
  • @staphhelpme If you have other question, you need to ask new one with explaining all the details so it would be clear – Marcin Nabiałek Oct 03 '14 at 12:09
  • @MarcinNabiałek Okay sir. Again, Thank you so much for your time and help! Really appreciate it! – staphhelpme Oct 03 '14 at 12:11