简体   繁体   English

空搜索结果Laravel 4

[英]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. 我正在制作一个简单的搜索引擎,其中,如果从下拉列表中选择的列表与数据库中“ destinationto”列中的列表匹配,则它将获取该行中的所有项目。 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: 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 : 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 只是一个猜测,但您应确保只有一个表单名称为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); 如果您认为还可以,则应添加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: 我以为select会将值用作键,但事实并非如此,因此您可能应该执行以下操作:

$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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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