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')代码>