skip to Main Content

i was working with laravel 8 and php 7 and there is a simple block of code in my view like below :

<h6 class="mt-3">{{$specialNews->up_title}}</h6>

now i updated my php to version 8 and when i hit the route i get this error :

Attempt to read property "up_title" on null (View: C:wamp64wwwresourcesviewswelcome.blade.php)

before that it was null safe it self . now the number of these variables are alot like 100 and i dont want to null safe all with ?? null is there any way to skip this error and is it because of php 8 ??

2

Answers


  1. use this: {{$specialNews ? $specialNews->up_title : ''}}

    Login or Signup to reply.
  2. To skip this error on PHP 8, use null-safe property operator ?->.

    <h6 class="mt-3">{{$specialNews?->up_title}}</h6>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search