Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

birdietorerik's avatar

Get only notifications from date now

Hi!

Have this function that are working 100%

public function NotificationsFlow()
    {
        $user =  auth()->user();
        return $user->unreadNotifications;
    }

But only want to return unreadnotifications from date today Like:

public function NotificationsFlow()
    {
        $user =  auth()->user();
        return $user->unreadNotifications->where('created_at'==='2023-07-05');
    }

But this dosent work, i have 2 record with date 2023-07-05

How do i do this ?

0 likes
5 replies
tisuchi's avatar

@birdietorerik I believe created_at is a timestamp that contains YYYY-MM-DD HH:MM:SS.

In that case, you can use whereDate() like that:

return $user->unreadNotifications->whereDate('created_at', '2023-07-05');
1 like
birdietorerik's avatar

@tisuchi Hi! Dosent know whereDate

Error:

"message": "Method Illuminate\Notifications\DatabaseNotificationCollection::whereDate does not exist.",
1 like
tisuchi's avatar
tisuchi
Best Answer
Level 70

@birdietorerik How about this?

public function NotificationsFlow()
{
    $user = auth()->user();
    $today = now()->toDateString();
    return $user->unreadNotifications->where('created_at', '>=', $today);
}
1 like
mrbegginerak's avatar

@birdietorerik

use Carbon\Carbon;

$notifications = $user->unreadNotifications->whereDate('created_at', Carbon::parse('2023-07-05')->toDateString());
1 like

Please or to participate in this conversation.