I have notification classes called ProductNotification, OrderNotification, etc, these have a mail method which returns another class which holds further data for the sending of emails:
class ProductNotification {
public function mail()
{
return ProductMail::class;
}
}
class OrderNotification {
public function mail()
{
return OrderMail::class;
}
}
Is there a way to instantiate the ProductMail class from the method, the following doesn't work and I'm not sure how to pass through another variable $data to the constructo.?
class BaseNotification {
public function toMail()
{
return (new $this->mail())->to($email)->send();
{
}
I know that if mail() was a property on the class instead, that this would be possible and I can pass through $data to the constructor as the following works, but is this possible from a method?
class ProductNotification {
public $mail = ProductMail::class;
}
class BaseNotification {
public function toMail()
{
return (new $this->mail($data))->to($email)->send();
{
}
mail()methodreturn new ProductMail();?toMailand then instantiate the variable.$datathrough to the ProductMail constructor, I've already shown that I am aware that I can store it as a property. But because of the way other parts of the class is structured, it would be cleaner to keep things consistent by keeping it as a method.