简体   繁体   中英

Empty search results Laravel 4

I am making a simple search engine in which, If the selected list from the dropdown would match with the one inside the 'destinationto' column from the database then it would fetch all the items inside that row. But when I hit the find button, it would not return any item from the database. It would be giving me an empty array.

 object(Illuminate\Database\Eloquent\Collection)[141]
  protected 'items' => 
    array (size=0)
      empty

What have I done wrong?

Here are the snippets

OnewayflightControllers.php:

 public function onewayflightresults()
 {
  $destinationto = Input::get('destinationto');
  $results = Oneways::where('destinationto','=',$destinationto)->get();   
  var_dump($results);
 }
 public function onewayflight()
{ 
  $onewaysfrom = DB::table('oneways')->distinct()->lists('destinationfrom');
  $onewaysto = DB::table('oneways')->distinct()->lists('destinationto');
  return View::make('content.onewayflight')->with(['destinationfrom'=>$onewaysfrom,'destinationto'=>$onewaysto]);
}

onewayflight.blade.php :

{{ Form::label('destinationto','To: ') }} 
{{ Form::select('destinationto', $destinationto)}}

It's only a guess but you should make sure you have only one form element with name destinationto

If you have in form for example

{{ Form::label('destinationto','From: ') }} 
{{ Form::select('destinationto', $destinationfrom)}}

{{ Form::label('destinationto','To: ') }} 
{{ Form::select('destinationto', $destinationto)}}

If you think it's ok, you should add var_dump($destinationto); to your function to make sure value is what you expect

EDIT

I thought select will use values as keys but it's not so you should probably do something like that:

$onewaysfrom = DB::table('oneways')->distinct()->lists('destinationfrom','destinationfrom');
$onewaysto = DB::table('oneways')->distinct()->lists('destinationto','destinationto');

and not:

$onewaysfrom = DB::table('oneways')->distinct()->lists('destinationfrom');
$onewaysto = DB::table('oneways')->distinct()->lists('destinationto');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM