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:
MailMessage
classMailMessage
class transforming our data to be compatible with the email APIAnd 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...