Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use this with Laravel Vapor #29

Open
ryanhungate opened this issue Apr 18, 2020 · 4 comments
Open

Can't use this with Laravel Vapor #29

ryanhungate opened this issue Apr 18, 2020 · 4 comments

Comments

@ryanhungate
Copy link

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?

@matthewhutchings
Copy link

Ah just seen this - if thats the case I can't use this package.

@ryanhungate
Copy link
Author

@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'),
        ];
    }
}

@nea
Copy link

nea commented Oct 23, 2021

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

@ryanhungate
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants