2
I’m having problems with a relative search on Laravel
. I give option of several searches on the screen, are they:
- initial date
- final date
- status,
- and whose is
but one can search in a unitary way, for example: I want to take all with status
Active, or all of a particular person, and so on.
Two of this search are mandatory, ie in all cases will have the initial date and final.
In the Controller
I’m getting this data I’m doing so:
$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 account that the data may or may not come and this needs to be addressed when doing the research?
my date in the bank has day, month, year, hour, second, minute and in my research it has only day and year, it has importance this ?
– Renan Rodrigues
All research cases are coming back empty, even if there are some results
– Renan Rodrigues
I think you’re in trouble at the moment
– Renan Rodrigues
found the error, I was confusing the date items, the right is >= after <=. It worked perfectly now.
– Renan Rodrigues
@Renanrodrigues now that I saw your comments. kkk
– novic