I have a model with four relations like as below
public function custform_formfields()
{
return $this->hasOne(FormFieldMapping::class,'field_id','field_id');
}
public function custform_fieldtype()
{
return $this->hasOne(FieldType::class, 'fieldtype_id', 'html_field_type');
}
public function custform_forms()
{
return $this->hasOne(CustomForms::class,'form_id', 'form_id');
}
public function custform_options()
{
return $this->hasOne(FormOptions::class,'option_id', 'option_id');
}
$model::with('custform_formfields','custform_fieldtype','custform_forms','custform_options')->whereRelation('custform_formfields',function($q) use ($whereArray) {};
But when i search with field name CustomFormsform_name it is giving me error
multi part identifier could not be identifed. Any idea I can search with any parameter including all 4 relationships. Currnetly whereRelation is accepting only function at a time.
3
Answers
to search through relation you need to use whereHas foreach relation take look here
From your Situation I understand that You can achieve the result by defining relation column on which you want to filter. Here Is My Example Code.
You’ll want to use
->whereHas()
: docs here.