空搜索结果Laravel 4


Empty search results Laravel 4

我正在制作一个简单的搜索引擎,如果从下拉列表中选择的列表与数据库中"destinationto"列中的列表匹配,那么它将获取该行中的所有项目。但是当我点击查找按钮时,它不会返回数据库中的任何项目。这会给我一个空数组。

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

我做错了什么?

以下是的片段

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)}}

这只是猜测,但您应该确保只有一个名为destinationto 的表单元素

如果你有形式,例如

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

如果您认为可以,您应该将var_dump($destinationto);添加到您的函数中,以确保值是您期望的

编辑

我认为select会使用值作为密钥,但事实并非如此,因此您可能应该这样做:

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

而不是:

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