webfuelcode
1 month ago
207
3
Laravel

Is this the correct way to display unread notification?

Posted 1 month ago by webfuelcode

I am little confused if it is correct or not. As I am showing a page for all unread notification and not sure about the auth.

Please look and make it correct if wrong. Or you know the correct way to do this.

Controller side is here:

$notifications = auth()->user()->unReadNotifications;
        foreach($notifications as $notification)
        {
            //dd ($notification);
            return view('profile.notifications', compact('notification'));
        }

View side is here:

            @foreach(Auth::user()->unReadNotifications as $notifications)
                {{ $notifications->data['user']['name'] }}
                commented on
                {{ $notifications->data['thread']['subject'] }}
                 - {{ $notifications->data['user']['created_at'] }}<br>
            @endforeach

The actual part where I am confused is, the auth. Do I need to use auth()->user() on both of the pages...

Please sign in or create an account to participate in this conversation.