1
I need to do a survey using like in a model that has relationship with another table(equipment). What has happened is that it is bringing all the records of the ordemservic table with the null related table (equipment) and in one of the records comes the related equipment. You’re not getting Where. Can you help me? I was clear?
Look at:
$pesquisa = $dataForm['pesquisa'];
//dd($pesquisa);
$data = Ordemservico::with([
'equipamento' => function ($query) use ($pesquisa) {
$query->where('codigoequipamento', 'LIKE', '%117%');
},
])->get();
dd($data);
I left the 117 fixed but still brings all the work orders!.
Thank you
Put the example of the two tables and their respective Model
– novic
$fillable = ['codigoequipamento', 'descricaoequipamento', 'centrocusto_id', 'tipoequipamento_id', 
 'tipogas_id', 'local_id', 'tipolocal_id', 'fornecedor_id', 'fabricante_id', 'modelo', 'patrimonio', 'numeroserie', 
 'dataaquisicao', 'notafical', 'valoraquisicao', 'dataagarantia', 'tag', 'btu', 'tr', 'hp', 'active']; public Function Rules($id = ') { Return [ 'codigoequipamento' => 'required|min:3|max:25', 'descricaoequipamento' => 'required|min:1|max:190', 'tag' => 'required|min:1|max:190',
– Marcos Birro
class Ordemservico extends Model {
 protected $fillable = ['user_id', 'colaborador_id', 'centrocusto_id', 'local_id', 'tiposolicitacao_id', 'dataplanejamento',
 'dataencerramento', 'tiposervico_id', 'checklist_id', 'descricaopadrao', 'prioridade_id', 'equipe1', 'equipe2', 
 'equipment_id', 'equipe_id', 'descricaoservico', 'dataultimaexecucao', 'periodicity', 'frequencia_id', 'impedimento_id', 'dataexecucao', 'attachment'];
– Marcos Birro
$search = $dataForm['search']; //dd($search); $data = Ordemservico::whereHas([ 'equipment' => Function ($query) use ($search) { $query->Where('codigoequipamento', 'LIKE', "%$search%"); }, 'local', 'typosolicitacao', ])->get();
– Marcos Birro
in your question! edit your question and put it all there!
– novic
maybe here lives the problem
$query->where('codigoequipamento', 'LIKE', '%117%');
because this filter, this codeequipment is the key to the relationship?– novic