我不完全確定問題是什麼,因爲我不明白我收到的錯誤消息。雄辯的關係故障檢索「belongsTo」關係
我有我的汽車模型下面的關係
/**
* The dealer the vehicle belongs to (one-to-one relationship)
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function dealer()
{
return $this->belongsTo('App\Dealer');
}
/**
* The vehicle's specifications
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function specifications()
{
return $this->hasMany('App\Specification');
}
如果我打電話的時候,有一個在$請求我收到以下錯誤「省」下面的方法:缺少參數2應用程序\項目\前端\回購\車輛\ EloquentVehicle ::應用程序\項目\前端\回購\車{關閉}()
我也收到錯誤,當有一個「城市」的請求。
public function vehicleSearchResults($request)
{
$allowedInput = array(
'year',
'make',
'model',
'city',
'province',
'price',
'Vehicle Type'
);
$query = $this->vehicle;
foreach($allowedInput as $value)
{
if($request->has($value))
{
switch ($value)
{
case 'year':
$query = $query->where('model_year', $request->input($value));
break;
case 'make':
$query = $query->where('make', $request->input($value));
break;
case 'model':
$query = $query->where('model', $request->input($value));
break;
case 'price':
$query = $query->where('price', $request->input($value));
break;
case 'city':
$query = $query->whereHas('dealer', function($subQuery, $request, $value)
{
$subQuery->where('city', $request->input($value))
->where('province', $request->input('province'));
})->with('dealer');
break;
case 'province':
$query = $query->whereHas('dealer', function($subQuery, $request, $value)
{
$subQuery->where('province', $request->input($value));
})->with('dealer');
break;
case 'Vehicle Type':
$query = $query->whereHas('specifications', function($subQuery, $request, $value)
{
$subQuery->where('spec', $value)
->where('spec_value', $request->input($value));
})->with('specifications');
break;
}
}
}
return $query->paginate(10);
}
我不知道錯誤的含義是什麼,但它指向省代碼中的這個代碼行。
$query = $query->whereHas('dealer', function($subQuery, $request, $value)
你錯過了'with('specifications')的回調''必須'with'('specifications',function(specifications){})'也是'('經銷商')' – Beginner