I'm not entirely sure what the problem is because I don't understand the error message I'm receiving.
I have the following relationships on my Vehicle model
/**
* 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');
}
If I call the method below when there's a "province" in the $request I get the following error: Missing argument 2 for App\Project\Frontend\Repo\Vehicle\EloquentVehicle::App\Project\Frontend\Repo\Vehicle{closure}()
I also get the error when there's a "city" in the request.
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);
}
I have no idea what the error means, but it points to this code line in the province switch case.
$query = $query->whereHas('dealer', function($subQuery, $request, $value)