2
I have a form with a field like month
, that sends a value in the format Y-m
for my controller. How do I search the records for the selected month and year?
I’m using L5-Repository
I did it this way, but it doesn’t work:
$date = Input::get('date');
$type = Input::get('type');
$values = $this->repository->findWhere(['type' => $type, 'date' => $date]);
From the following error:
Queryexception in Connection.php line 761: SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type date: "2016-09" (SQL: select * from "values" Where "type" = Recipe and "date" = 2016-09)
I thought I was going to make that mistake, but I don’t know how to make it work. Someone gives a light?
I’m using Postgres database and the field date is in format date
even.
Just one question outside the scope of the topic: why are you using this Repository ?
– Diego Souza
So @Peterparker honestly wouldn’t know how to explain to you right because I’m still studying this in a course, but it serves to abstract the data layer. I haven’t done anything very big yet, but from what I understand it’s easier to keep the application that way, not dealing with the model directly in the controller. Sorry I can’t explain it properly =/
– Raylan Soares
There’s actually a way simpler. Just use
whereYear
andwhereMonth
.– Wallace Maxters