Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 从查询中获取空集合_Laravel_Laravel 5_Laravel 5.1 - Fatal编程技术网

Laravel 从查询中获取空集合

Laravel 从查询中获取空集合,laravel,laravel-5,laravel-5.1,Laravel,Laravel 5,Laravel 5.1,我有一个疑问: $amount = Input::get('amount'); // First getting the age range from the input in html (name="amount"). $amount = str_replace(' ','',$amount); //remove the blank spaces between the ages value, if there's any. $amount = explode(

我有一个疑问:

$amount = Input::get('amount'); // First getting the age range from the input in html (name="amount").
        $amount = str_replace(' ','',$amount); //remove the blank spaces between the ages value, if there's any.
        $amount = explode('-',$amount); // is breaking the value 16-45, as 16 and 45, '-' being the breaking point. And finally turns the value into array.

        // Getting the array value as index 0 and 1.
        $min = $amount[0];
        $max = $amount[1];

        $user = $request->user();
        $userSelect = Input::get('select_preferences');
        $prefQuery = Profile::whereHas('expectations', function($query) use($userSelect) {
        $query->whereIn('name', $userSelect); // First Query: compare the name column in expectations table with the user selection.
        //now chain another query:
        })->whereBetween('age', [$min,$max])    
        ->with('user', 'expectations')->get();
我正在尝试获取用户选择和年龄范围。运行
dump($prefQuery)时-我得到的是空集合:

Collection {#192 ▼
  #items: []
}
以下是要查询的配置文件模型:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class profile extends Model
{
  protected $table = 'profiles';

  protected $fillable = ['gender','age','goals','activityType'];


  /**
   * A profile belongs to many Expectations
   * @return Illuminate\Database\Eloquent\Relations\BelongsToMany
   */
  public function expectations()
  {
      return $this->belongsToMany('App\Expectation');
  }

  /**
   * A profile is belong to a user
   * @return Illuminate\Database\Eloquent\Relations\BelongsTo
   */
  public function user()
  {
    return $this->belongsTo('App\User'); //belongsTo relationship from your Profile model to your user model.
  }
}

您是否获得了
$amout
?Laravel 5.1使用
Request Facade
检索输入:
Request::input('amount')供参考。在上述代码中,您使用的是来自Laravel 4.2的过时代码来检索金额:
$amount=Input::get('amount')@OliverQueen抱歉我已经做了。下面是完整的代码:在代码的第4行,您仍然使用不推荐的版本来检索金额。它应该是:
amount=$request->input('amount')