1

我正在制作一个简单的搜索引擎,如果从下拉列表中选择的列表与数据库中“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)}}
4

1 回答 1

1

这只是一个猜测,但您应该确保您只有一个带有名称的表单元素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');
于 2014-10-03T15:16:04.547 回答