Eloquent: "WHERE (equals statement) AND (LIKE statement)"

Luke West

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

Dilip Patel

Try this, it should work:

m_requests::where('id', '=', Auth::user()->id)
            ->where('created_at', 'LIKE', '%'.date("Y-m-d").'%');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related