I have a situation in which I need to customize or rather add some buttons in emails going to a specific set of users, let's say we have normal users and investors and I have some notification classes that send emails to investors. In these Notification classes, I'll need to add some links they can click on to view some resources for them only.
I created a MailMessage class that extends Laravel's MailMessage class with a method target()
<?php
namespace App\Notifications\Messages;
use Illuminate\Notifications\Messages\MailMessage as MessagesMailMessage;
class MailMessage extends MessagesMailMessage
{
/**
* The target audience.
*
* @var string
*/
public $target;
/**
* Set the target audience for the mail message.
*
* @param string $target
* @return $this
*/
public function target(string $target)
{
$this->target = $target;
return $this;
}
}
then in the notification class, I used the new MailMessage class which I created that still extends Laravel's MailMessage
use App\Notifications\Messages\MailMessage;
class InvestorNotification extends Notification implements ShouldQueue
{
use Queueable;
protected $investment;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Investment $investment)
{
$this->investment = $investment;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage())
->target('investor')
->line('Thank you for choosing us!');
}
but in the /resources/view/vendor/notification/email.blade.php
I tried to check if $target exists and then display the buttons but the $target is not returning as undefined
please help in any way you can