0

UsersController:

public function notifications(){
    auth()->user()->unreadNotifications->markAsRead();
    return view('users.notifications',[
            'notifications' => auth()->user()->notifications()->paginate(5)
    ]);
}

notifications.blade.php:

@foreach ($notifications as $notification)

   <a href="{{ route('discussions.show', $notification->data['discussion']['slug'])}}" class="btn btn-outline-info btn-sm btn float-right">View Discussion</a>

@endforeach

The Error is giving from this code

$notification->data['discussion']['slug']

Trying to access array offset on value of type null (View: C:\xampp\htdocs\laravel-forum\resources\views\users\notifications.blade.php)

2
  • What does your $notification object contain? Commented Apr 16, 2020 at 10:35
  • It was working completely fine, but when i ran composer update. and updated my laravel php etc. it stopped working. I guess i have to downgrade my php to 7.3 but dont have a clue how Commented Apr 16, 2020 at 12:33

1 Answer 1

0

It looks like some of your notifications doesn't have discussion or slug properties. First of all check your notifications data in your DB. If you don't need this notifications to be visible move this HTML tag into 'if' condition and check @if(isset($notification->data['discussion']['slug'])).

Sign up to request clarification or add additional context in comments.

1 Comment

Yes i know how the database notifications structure in Laravel looks like but data is a JSON field and some of the prorperties in this json could be invalid for any reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.