Luke West
Luke West

Reputation: 53

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

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

Upvotes: 5

Views: 10209

Answers (1)

Dilip Patel
Dilip Patel

Reputation: 832

Try this, it should work:

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

Upvotes: 4

Related Questions