Open ryanhungate opened 4 years ago
Ah just seen this - if thats the case I can't use this package.
@matthewhutchings i ended up just extending the 2 classes and overriding the methods so that it didn't try to save the file to the disk, and made sure to add the namespace right before the markdown was rendered. That ended up working for the Nova Actions.
<?php
namespace App\Services\Nova\Actions;
use Illuminate\Support\Facades\Mail;
use KirschbaumDevelopment\NovaMail\Mail\Send;
class SendMail extends Send
{
/**
* Build the message.
*
* @return $this
*/
public function build()
{
view()->addNamespace('mail', [
resource_path('views/vendor/mail/html'),
]);
return $this->markdown([
'template' => $this->content,
'cache_key' => "send_mail_{$this->model->id}",
'secondsTemplateCacheExpires' => 0,
'templateRefKey' => 'SendMail: Build function'
], $this->model->toArray());
}
/**
* Execute delivery.
*
* @return $this
*/
public function deliver()
{
$this->subject($this->subject);
Mail::send($this);
return $this;
}
}
<?php
namespace App\Nova\Actions;
use App\Services\Nova\Actions\SendMail;
use Illuminate\Bus\Queueable;
use Laravel\Nova\Actions\Action;
use Illuminate\Support\Collection;
use Laravel\Nova\Fields\ActionFields;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use KirschbaumDevelopment\NovaMail\Models\NovaMailTemplate;
use KirschbaumDevelopment\NovaMail\SendMail as SendMailField;
/**
* Class SendMailToUser
* @package App\Nova\Actions
*/
class SendMailToUser extends Action
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* @param ActionFields $fields
* @param Collection $models
* @return array
*/
public function handle(ActionFields $fields, Collection $models)
{
$mailOptions = json_decode($fields['mail'], true);
if (isset($mailOptions['selectedTemplate']) && isset($mailOptions['selectedTemplate']['id'])) {
$template = NovaMailTemplate::findOrFail($mailOptions['selectedTemplate']['id']);
} else {
return Action::danger("You must select a template in order to send the message.");
}
$models->each(function ($model) use ($mailOptions, $template) {
$mailable = new SendMail(
$model,
$template,
$mailOptions['body'],
$model->{$model->getEmailField()},
$mailOptions['subject'] ?? config('app.name')
);
$mailable->deliver();
});
}
/**
* Get the fields available on the action.
*
* @return array
*/
public function fields()
{
return [
SendMailField::make('Mail'),
];
}
}
Ahoi @ryanhungate , @matthewhutchings and those that stumble over this:
I used the solution found here https://laracasts.com/discuss/channels/vapor/zipping-file-on-laravel-vapor?page=1&replyId=617247 by creating a 'tmp' disk and assigning this disk to the 'compiled_mail_disk' and it works now on Vapor, too.
I, too, have overriden the Send Class and Mail Action to accompany for everything.
Cheers
Sure that makes sense @nea - It's been a while since I needed to work with this. I can't recall why the file needed to be saved in the first place. Seems like a sensible configuration for this could be made so we don't need to hunt down solutions and override things like this :)
Any option to change the behavior using the filesystem to possibly something else that would work with Laravel's Vapor service? Seems as if the reliance on the filesystem is a problem - or maybe i'm missing something small. Any advice?