smzapp
smzapp

Reputation: 839

How to limit unreadNotifications in Laravel?

the code below displays all the unread notifications of a logged in user in laravel:

auth()->user()->unreadNotifications

I put the code into a tag and bind it as unreads property so that my vue component can access the unreads data.

<notification :userid="{{ auth()->user()->id }}" :unreads="{{ auth()->user()->unreadNotifications }}"></notification>

Everything works fine.

From the vue js, I can limit the unreads data to the number results I want.

However, when I view the source code in a browser, I can see the all notifications are displayed, hence, delaying of page load since there are a lot of results on it.

Now, I want to LIMIT auth()->user()->unreadNotifications so that I can control the number of results to be displayed. I checked on google and laravel docs, but I found none. Does anybody know?

Upvotes: 3

Views: 2353

Answers (1)

Mike S
Mike S

Reputation: 1646

There is an issue on the Laravel Framework GitHub that suggests you could use:

auth()->user()->unreadNotifications()->take(10)->get()

Source: https://github.com/laravel/framework/issues/18789

Upvotes: 7

Related Questions