Latest

Thursday, July 6, 2017

Undefined index: user when I display notification json array in laravel

Asked by: DevTaabi


When try to display the json data it gives the Undefined index: user exception

  foreach(auth()->user()->unreadnotifications as $notifications)

       @include('frontend.common.notification.'.snake_case(class_basename($notifications->type)))

  @endforeach

Included view code is

  <div>
    <i class="fa fa-comment fa-fw"></i>
    <img src="{{url('images/account/'.$notifications->data['user']['currentimage'])}}" height="50px" width="50"/>
    {{$notifications->data['user']['email']}} commented on your post.
    <span class="pull-right text-muted small">{{$notifications->created_at->diffForHumans()}}</span>
</div>

Json Object is

{"comment":{"comment":"I am awesome","user_id":2,"post_id":"2","commment_rate":90,"updated_at":"2017-07-06 16:32:07","created_at":"2017-07-06 16:32:07","id":18},"user":{"id":2,"email":"test2@mail.com","currentimage":"1499004938.jpg","role":0,"verified":null,"blocked":null,"created_at":"2017-07-02 13:44:24","updated_at":"2017-07-02 14:15:38"}}



Source

No comments:

Post a Comment

Adbox