I am doing a search by taking a word part and playing in a search type LIKE
for fields fields. I use Eloquent
and relationships, but it does not bring the data.
{
$pesquisa = $dataForm['pesquisa'];
$atestados = Atestado::with([
'colaborador' => function ($query) use ($pesquisa) {
$query->where('colaboradors.matricula', 'LIKE', "%{$pesquisa}%")
->orWhere('colaboradors.nome', 'LIKE', "%{$pesquisa}%");
},
'cid' => function ($query) use ($pesquisa) {
$query->orWhere('cids.codigo', 'LIKE', "%{$pesquisa}%");
},
'situacao' => function ($query) use ($pesquisa) {
$query->orWhere('situacaos.descricao', 'LIKE', "%{$pesquisa}%");
},
])
->orderBy('data_afastamento', 'desc')
->get();
}