Closed jbraband closed 4 years ago
PR is submitted. I'm more than willing to help refine it!
Here is how that is used. A sample custom Mailable:
<?php
namespace App\Mails;
use Illuminate\Queue\SerializesModels;
use Spatie\Mailcoach\Mails\CampaignMail;
class SingleArticle extends CampaignMail
{
use SerializesModels;
protected int $article_id;
public function __construct($article_id)
{
$this->article_id = $article_id;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$article = code_fetch_article_data($this->article_id);
return $this->view('single-article', compact('article'));
}
}
And this code to build the campaign and pass the Mailable and arguments:
$campaign = Campaign::create()
->useMailable(SingleArticle::class, ['article_id' => 1000]);
We'll merge the PR when we'll start working on v3 in a couple of months.
My thinking with this is to add a mailable_arguments column to mailcoach_campaigns database table. It'll be the json datatype.
Campaign::useMailable() becomes this
Campaign::getMailable() becomes this
CampaignMail would need a constructor to take the arguments array and set it to a protected property. Now the build() method of our custom mailables have arguments injected into it from the Campaign.
I'm willing to put this together. I need this functionality and I think it makes sense to allow custom mailables to be parameterized from the developer's application.
my use case for parameterized Mailables is a campaign that sends emails about one specific article on our website. That article's id would be passed as an argument in this manner:
Any modifications to this idea before I get to work on it?