Maren Maren
Maren Maren

Reputation: 69

Update record where created_at is today - Laravel

I tried a solved questions from this site, but for me nothing worked.

This is the code

Items::where('item_id', $item->id)->where('created_at', \Carbon\Carbon::today()->toDateString())->update(['item_price' => $price]);

Items::where('item_id', $item->id)->where('created_at', \Carbon\Carbon::today())->update(['item_price' => $price]);

Is there something I missed?

Upvotes: 2

Views: 113

Answers (2)

Jaber Al Nahian
Jaber Al Nahian

Reputation: 1061

For Laravel 5.6+, you can simply do something like:

Items::where('item_id', $item->id)->where('created_at', \Carbon\Carbon::today())->update(['item_price' => $price]);

or

Items::where('item_id', $item->id)->where('created_at', Carbon::today())->update(['item_price' => $price]);

Upvotes: 0

Maren Maren
Maren Maren

Reputation: 69

@TimLewis answered

use ->whereDate() if you use ->toTimeString(), or ->where() with a Carbon variable

Upvotes: 1

Related Questions