I'm having trouble with a relative search on Laravel
. I give the option of several on-screen search, they are:
- start date
- end date
- status,
- and who it is
But the person can search in a unitary way, for example: I want to get everyone with status
Active , or all of a certain person , and so on.
Two of this survey are required, ie in all cases they will have the start date and end .
In Controller
I'm getting this data I'm doing this:
$inicial = DateTime::createFromFormat('d/m/Y', $request->get('dataInic'))->format('Y-m-d');
$final = DateTime::createFromFormat('d/m/Y', $request->get('dataFim'))->format('Y-m-d');
$flgStatus = $request->get('FlgStEncomenda');
$pessoa = $request->get('CdPessoa');
$clientes = Pessoa::lists('NmPessoa', 'id')->all();
$pedidos = Encomenda::where('created_at', '<=', $inicial)
->where('created_at', '>=', $final)
.(($flgStatus == 'null')? '' : "->('FlgStEncomenda', ".$flgStatus.")")
.(($pessoa == '')? '->get()' : "->('CdPessoa', ".$pessoa.")");
When doing this the screen returns me the following error :
Object of class Illuminate \ Database \ Eloquent \ Builder could not be converted to string.
What is the best way to do this research, taking into consideration that the data may or may not come and this needs to be addressed when doing the research?