I want to filter a table by user ID and the created_at field. The only thing is created_at is a timestamp, and I want to query by date only not time.
So something like -
$messages = Message::where(['from' => $fromUser->id, 'created_at' => 'TODAY'S DATE'])->get();
Timestamps allows you to automatically record the time of certain events against your entities. This can be used to provide similar behaviour to the timestamps feature in Laravel's Eloquent ORM.
You either have to declare public $timestamps = false; in every model, or create a BaseModel, define it there, and have all your models extend it instead of eloquent.
$query->whereDate('created_at', '=', date('Y-m-d'));
or
$query->whereDate('created_at', '=', Carbon::today()->toDateString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With