Courses

Design Patterns in Laravel 11

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...

This lesson is only for Premium Members.
Want to access all lessons of this course?

You also get:

  • 68 courses (1183 lessons, 43 h 18 min total)
  • Premium tutorials
  • Access to repositories
  • Private Discord