TL;DR Does anyone know how to inject the Xinax\Gettext dependencies into the Mail-closure?
I have a setup with Laravel 5.1 and the Xinax Gettext
package (http://ift.tt/1Ngew03) which works perfectly for translating strings, except for when running an artisan command which attempts to send an email containing a model.
In my model I have a few attribute mutators, for example:
MyModel.php
public function getTranslatedStringAttribute(){
return _('Translated string');
}
The command calls a repository which sends an email, like this:
public function sendEmailFromRepository(){
$modelsToInclude = \App\Models\MyModel::get();
\Mail::queue('emails.myTemplate', ['theData' => $modelsToInclude], function ($message) {
$message->from('no-reply@example.org', 'App name');
$message->to('test@exmaple.org');
$message->subject('Delivering some stuff to you');
});
}
Here's the issue, this gives me:
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined function App\Models\_()
I've figured this is probably because of the \Mail::queue-closure creating a scope which is isolated from the autoloaded helpers, Xinax\Gettext included. Does anyone know how to inject the gettext dependencies into the Mail-closure, or have any other clues on what may be my problem?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire