stackkit / laravel-database-emails

Store e-mails in the database and send them using a cronjob
MIT License
38 stars 6 forks source link

Always expecting a view #45

Closed jamesautodude closed 9 months ago

jamesautodude commented 1 year ago

When using:

Email::compose() ->mailable(new OrderShipped()) ->send();

I get an error of: View [] not found.

jamesautodude commented 1 year ago

I haven't heard anything back :/ but that's alright

For anyone else, the workaround is just to not use the above mailable example, since I guess it's not going to be fixed :/

Before package example

For reference, this is how I was doing it before the package

I use the database to store my mailable templates so, this is how I do that with regular laravel:

//use helper to grab the subject from mailable table with column "mailable" as "ClientSignup" and column "subject"
$subject = emailTemplate($companyInfo->id, 'ClientSignup', 'subject'); 

//use helper to grab the body from mailable table with column "mailable" as "ClientSignup" and column "html_template"
$body = emailTemplate($companyInfo->id, 'ClientSignup', 'body');

Mail::to($request->email)->send(new DatabaseMailer($body, $subject));

The above Mail::to works perfectly

What I expected I could do it with this package

Based on readme I though I could do the following...

//use helper to grab the subject from mailable table with column "mailable" as "ClientSignup" and column "subject"
$subject = emailTemplate($companyInfo->id, 'ClientSignup', 'subject'); 

//use helper to grab the body from mailable table with column "mailable" as "ClientSignup" and column "html_template"
$body = emailTemplate($companyInfo->id, 'ClientSignup', 'body');

Email::compose()
->mailable(new DatabaseMailer($body, $subject))
->send();

Unfortunately it gives View[] not found

Workaround

I will use the following for now, which isn't a bad thing... just posting for reference

//use helper to grab the subject from mailable table with column "mailable" as "ClientSignup" and column "subject"
$subject = emailTemplate($companyInfo->id, 'ClientSignup', 'subject'); 

//use helper to grab the body from mailable table with column "mailable" as "ClientSignup" and column "html_template"
$body = emailTemplate($companyInfo->id, 'ClientSignup', 'body');

Email::compose()
  ->label('welcome')
  ->recipient('test@gmail.com')
  ->subject($subject)
  ->view('emails.databaseTemplate')
  ->variables([
      'body' => $body,
  ])
  ->send();

This workaround works fine

Thank you

marickvantuil commented 10 months ago

Sorry, I can't reproduce this using fresh installs of Laravel 8, 9 or 10! Few questions: