4

I basically want to do:

select * from request where id = 1 and created_at like (today's date);

but using eloquent.

I tried:

 $query = m_requests::where(['id' => Auth::User()->id, "created_at", "like", "%".date("Y-m-d")."%"]);

but that returns the error:

SQLSTATE[42S22]: Column not found: 1054 Unknown
column '0' in 'where clause' (SQL: select * from
from `request` where (`id` = 1 and `0` = created_at 
and `1` = like and `2` = %2016-04-22%))

Does anyone know how I could achieve what I am trying to do?

In summary: I want the id to equal the id requested, but I want the date to be "LIKE" today's date (This is because I'm only interested in the date it was created and not the time it was created).

Cheers

Luke West
  • 43
  • 1
  • 5
  • You know that `timestamp` columns are not strings? You can't use `LIKE` with them, and it makes no sense. If you want the date to be somewhere during today, then you use `BETWEEN` operator and you give it the beginning and end date (`BETWEEN 2016-04-22 00:00:00 AND 2016-04-22 23:59:59`). – Mjh Apr 22 '16 at 12:38
  • I was just using that as an example. Didn't even check to see if it ran. Sorry, I'll edit it now (if I can). – Luke West Apr 22 '16 at 12:40
  • Possible duplicate of [Using Eloquent ORM in Laravel to perform search of database using LIKE](http://stackoverflow.com/questions/13386774/using-eloquent-orm-in-laravel-to-perform-search-of-database-using-like) – Pietro Apr 22 '16 at 12:45

1 Answers1

3

Try this, it should work:

m_requests::where('id', '=', Auth::user()->id)
            ->where('created_at', 'LIKE', '%'.date("Y-m-d").'%');
Ryan Vincent
  • 4,483
  • 7
  • 22
  • 31
Dilip Patel
  • 764
  • 15
  • 24