Intricacies of Sending an Invoice
Consider a task as simple as attaching an invoice to an email and sending it to a particular user. It's an incredibly common task, and yet, there are many, many steps involved. What should the invoice look like? How do you programmatically save it as a PDF? How do you attach it to an email? How might you test that the notification was properly sent?
If you're interested, come along as I work on this very task for the Laracasts codebase.
Progress
Series Info
- Episodes
- 5
- Run Time
- 38m
- Difficulty
- Advanced
- Last Updated
- Jan 27, 2022
- Version
- Latest
Series Episodes
- Episodes (5)
How to Convert HTML to PDF
To begin, we must first determine how to convert an existing piece of HTML to PDF. Luckily, this will be easier than you think, thanks to Spatie's Browsershot package.Send a Notification and Attach a PDF
Now that we know how to save any rendered Blade view as a PDF, let's next prepare a Laravel notification and attach the invoice PDF to it.Free Logic From the Controller
Newcomers will often inquire about how to trigger logic in a controller action from elsewhere in the codebase. But this isn't the right way to approach it. Instead, it's better to extract the relevant logic to a dedicated class, and then defer to it as a dependency.Refactoring Considerations
We moved pretty quickly in this series. With that in mind, let's take an episode to brush over each class in search of potential improvements.Notification Tests and Fakes
Let's wrap up this mini-series by demonstrating how we might test ourSendInvoicejob. Specifically, we should confirm that a notification is sent to the user each time the corresponding job is dispatched.
