Dispatching closure jobs after response can be a really nice way to do some cleanup 💅:
1$pdf->store('file.pdf');
2
3// Delete the file after the response has been sent
4dispatch(fn () => Storage::delete('file.pdf'))->afterResponse();
5
6return Zip::download('file.pdf');
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.