Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.4 change the subject of markdown mail

I have used markdown mailables which is a new feature in laravel 5.4. I have successfully implemented a mail sender. It seems, the subject of the mail is named as the name of the mailable class. I need to change the subject of the mail and it's hard to find any resources regarding this.

like image 306
Shashika Avatar asked Apr 17 '17 06:04

Shashika


2 Answers

There is subject method in laravel mailables.

All of a mailable class' configuration is done in the build method. Within this method, you may call various methods such as from, subject, view, and attach to configure the email's presentation and delivery. : https://laravel.com/docs/5.4/mail#writing-mailables

You can achieve this like this :

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from('[email protected]')
                ->subject('Your Subject')
                ->markdown('emails.orders.shipped');
}

You may need to execute php artisan view:clear after modifying your class.

like image 159
Pankit Gami Avatar answered Sep 28 '22 12:09

Pankit Gami


If the email subject is the same for all emails then just overload the $subject parameter in your extended Mailable class.

/**
 * The subject of the message.
 *
 * @var string
 */
public $subject;
like image 24
rStyles Avatar answered Sep 28 '22 11:09

rStyles