Laravel 4下拉列表

I've made a drop down list that takes 'destination-from' values on 'oneways' table from the database. Following this tutorial here: http://www.laravel-tricks.com/tricks/easy-dropdowns-with-eloquents-lists-method

But whenever I try to run it, It gives me this kind of error: Undefined variable: categories What seems to be the problem here? I am really new to this. A newbie on laravel.

Here are my codes:

onewayflight.blade.php

  $categories = Category::lists('destination-from', 'title');
      {{ Form::select('category', $categories) }}

onewayflightcontroller.php

  public function onewayflightresults()
{
  return View::make('content.onewayflight');

  $list = DB::table('oneways');
  $listname = Oneways::lists('destination-from');

  $content = View::make('content.onewayflight', array('list'=>$list, 'listname'=>$listname));
}

I am not really sure of what I have left out one this. And I am also wondering if the model has something to do with this?

The code in your template where you are fetching the categories needs to be surrounded by PHP tags otherwise it won't be executed. But better still - move it to your controller which is where it belongs.

Also in your controller you return the view at the top of your onewayflight() - nothing after this will be executed.

So change it work work like this and you should be ok:

onewayflight.blade.php

{{ Form::select('category', $categories) }}

onewayflightcontroller.php

 public function onewayflight()
 {
    $categories = Category::lists('destination-from', 'title'); 

    return View::make('content.onewayflight', array('categories' => $categories));
  }

Also, in routes.php the route should look like this:

Route::get('/your-route-path', [
    'as' => 'your_route_name',
    'uses' => 'onewayflightcontroller@onewayflight'
]);

Additionally to @jd182 's advice (as I lack the reputation to comment, I use answer); are you sure that lists() function/facade returns some value other than null. PHP, sometimes, considers null values as undefined.

And your blade syntax is wrong. if you want to define a variable inside a blade file (which is not advised) you should wrap it around tag and work it as a regular php file.