laravel - Use of Command inside of a service -
im using laravel 5.0 , attempting set command queueing job inside of mailer service.
my problem don't know how inject command dispatcher mailer service.
my structure:
- services folder
- mailer.php (contains abstract class mailer)
- usermailer.php (contains class usermailer extends mailer class)
things have tried:
i've tried use dispatchescommands trait within usermailer class , within mailer class. have tried inject \illuminate\contracts\bus\dispatcher constructer of usermailer class.
in 3 instances error "class services\mailers\sendemail not found"
mailer.php:
abstract class mailer { public function emailto($view, $mdata) { mail::queue($view, $mdata, function($message) use ($mdata) { //code here - not relevant } }); } }
usermailer.php:
use illuminate\contracts\bus\dispatcher dispatcher; class usermailer extends mailer { protected $bus; function __construct(dispatcher $bus) { $this->bus = $bus; } public function sendindividualemail($members) { // code here not relevant... $this->bus->dispatch(new sendemail($members)); return true; }
how access command bus within usermailer class? tia
you should import qualified namespaced path sendemail
class, example:
use illuminate\contracts\bus\dispatcher dispatcher; use namespace\to\sendemail; //<-- add "use" statement correct namespace class usermailer extends mailer { //... }
so, can use new sendemail($members)
within class. in code, php
looking sendemail
in services\mailers
namespace/folder.
Comments
Post a Comment