zubair malik
zubair malik

Reputation: 223

Trying to get property 'id' of non-object using laravel 8

I am trying to show notification but unfortunately i am getting error if work permit table has not record how can i resolve this issue ? thnaks.

Trying to get property 'id' of non-object (View: /home/zubair/htdocs/permit-to-work/cms/resources/views/cms/layouts/header.blade.php)

view blade

   @php
    $notifications = getNotication();
    @endphp
    @foreach ($notifications as $notification)
    <div class="notification-load">
    <a href="{{route('work.permit.edit',$notification->workPermit->id)}}" class="dropdown-item notify-item ">
    <div class="notify-icon bg-blue">
        <i class="fas fa-file-alt text-white">
        </i>
    </div>
    @php
    $date=$notification->workPermit->validty_to;
    $timestamp = strtotime($date);
    $validty_date = date("d,M ,Y", $timestamp);
    @endphp
    <p class="text-muted mb-0 user-msg ">
    <b>
    <small class="notification_list">Permit No {{$notification->workPermit->permit_code}}  validity is about to end at {{$validty_date}}
    </small>
    </b>
    </p>
    </a>
    </div>
    @endforeach

Upvotes: 1

Views: 103

Answers (1)

Mohammad Akbari
Mohammad Akbari

Reputation: 446

use this helper function

optional($notification->workPermit)->id

instead of that

$notification->workPermit

Upvotes: 1

Related Questions