【问题标题】:Empty search results Laravel 4空搜索结果 Laravel 4
【发布时间】:2014-11-28 15:59:09
【问题描述】:

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

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

我做错了什么?

这里是sn-ps

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 值中的行。否则,请告诉我们您填写的内容、$destinationto 中的 var_dump 是什么以及您的表格中有哪些数据
  • @MarcinNabiałek 先生,我已经编辑了我的问题。我在所有东西上都尝试了 var_dump,只有 $destinationto 没有给我任何结果。我可能犯了什么错误?

标签: php laravel laravel-4 blade laravel-form


【解决方案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');

【讨论】:

  • 我已经仔细检查了我的表单,并且只有一个名为 destinationto 的元素。尝试更改完全不同的名称并将其 var_dump ,但仍然没有任何反应。它返回'destinationfrom' => 字符串'0' (length=1) 'destinationto' => 字符串'0' (length=1)
猜你喜欢
  • 2019-06-30
  • 1970-01-01
  • 2021-09-19
  • 1970-01-01
  • 2017-02-24
  • 2018-11-19
  • 1970-01-01
  • 2017-01-12
  • 2017-09-29
相关资源
最近更新 更多