php - Laravel - Mailer Service? -
i'm bit of noob laravel i'm setting bug tracking system , have question how remove multiple instances of sending mails. let me show how i've got set currently:
public function store(usersrequest $request) { $user = user::create($request->all()); mail::queue('emails.master', ['user' => $user], function($message) use ($user) { $message->to('someone@somewhere.com') ->subject('new user created'); }); return redirect('/users'); }
so have method in controller creates new user in system, send mail out. i'd strip mail call out 1 line of code.
what's best way achieve this?
what i've found far, setting service handle - this: http://lukefair.com/create-a-mailer-service-with-laravel-and-a-basic-working-example-of-dependency-injection/
this seems idea noob brain , achieve need to. there better way creating service? making use of events perhaps (although, guess i'd still need service that)?
as said, i'm bit of laravel noob , haven't got these patterns , ways of doing things down yet.
any advice great. thanks!
the typical solution problems is, in laravel world @ least, create service provider. article linked fit looking do.
if want able access new mailer class globally can mail
, request
, of other familiar laravel facades, can create own , usable anywhere in application.
Comments
Post a Comment