You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use model created events to notifications that create a mailable. The model has some media from the user's upload.
I tried $mediaItems = $this->bdReport->getMedia(); in the attachments method but the $mediaItems is empty.
It looks like the media are not saved yet when the created event is dispatched. What can I do?
This is my code:
In mailable
public function attachments(): array
{
$mediaItems = $this->testReport->getMedia();
$attachments = [];
foreach ($mediaItems as $mediaItem) {
$attachments[] = $mediaItem;
}
return $attachments;
}
public function handle(TestReportCreated $event): void
{
Notification::send($event->testReport->createdBy, new NewTestReportNotification($event->testReport));
}
In notification
public function toMail(object $notifiable): Mailable
{
$mailable = new TestReportRaisedMailable($this->testReport);
$mailable->to($notifiable->email);
return $mailable;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I use model created events to notifications that create a mailable. The model has some media from the user's upload.
I tried $mediaItems = $this->bdReport->getMedia(); in the attachments method but the $mediaItems is empty.
It looks like the media are not saved yet when the created event is dispatched. What can I do?
This is my code:
In mailable
in model
In listener
In notification
Beta Was this translation helpful? Give feedback.
All reactions