Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Adapter: in Notifications and Filesystem

Premium
3 min read

We don't even have to dig too deep for this next pattern. We have to look at Notifications in Laravel:

Notification

public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Link button', route('link'));
}

In this example, we've transformed our data to be compatible with the MailMessage class, which will be used to send emails. This is the adapter pattern in action! There are two layers to it:

  1. We are transforming our data to be compatible with the MailMessage class
  2. The MailMessage class transforming our data to be compatible with the email API

And all of that is done seamlessly without us even knowing about it! We don't have to worry about the email driver or what data it expects. We have to...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.