1

I have created notification to store order submit event as

 return [
       'cart_id'=>$this->cart->id,
       'text'=>'order is submitted'
    ];

when i retrieve notifications data from database as

 @foreach (Auth::user()->unreadNotifications as $notification ) 
   {{$notification->data['text'] }}
 @endforeach 

this gives error as undefined index text

but if i try to access text via

@foreach ($notification->data as $key => $data)
{{$data}}
@endforeach 

it works

but why cant i can access data via $notification->data['text']

1 Answer 1

1

You should get the text attribute directly like :

@foreach (Auth::user()->unreadNotifications as $notification )
    {{ $notification->text }}
    //Or use
    {{ $notification['text'] }}
@endforeach 

Hope this helps.

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

2 Comments

Ok try please $notification->data->text
Try also json_decode( $notification->data )->text.

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.