Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change notification mail ->action function button default color Laravel?

I have a task. And in Notifications mail file I need to add a button in public function toMail():

I have done it, but by default, the background color of the button is black, and I need to make it blue. How do I change the color in this function and code of the button?

Here is the code exampple:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public function toMail(): MailMessage
{
return (new MailMessage())
->action('Button name', rout('route.name'))
}

SO how to change the button color that the background color change from default black to my choosing (for example blue)?

Thank you.

>Solution :

The SimpleMessage class is designed for creating simple messages that have one call to action button, you can find the code that powers the functionality in Illuminate/Notifications/Messages/SimpleMessage.php and the template for the SimpleMessage emails can be found in Illuminate/Notifications/resources/views/email.blade.php — note the single button.

You can create more complex messages using the Markdown Mail Notifications feature, which will allow you to include as many buttons as you like. You can implement this like so:

Run the command to generate a new notification and pass in the markdown option, e.g: php artisan make:notification InvoicePaid –markdown=mail.invoice.paid
Open the newly created template, e.g: views/mail/invoice/paid.blade.php
Add as many buttons as you like, e.g:

@component('mail::message')
  # Introduction

  @component('mail::button', ['url' => $url1])
  Button 1 Text
  @endcomponent

  @component('mail::button', ['url' => $url2])
  Button 2 Text
  @endcomponent

  @component('mail::button', ['url' => $url3])
  Button 3 Text
  @endcomponent

Thanks,
{{ config(‘app.name’) }}
@endcomponent
Replace your calls to SimpleMessage methods with a reference to your markdown template when constructing your email, e.g:

return (new MailMessage)
  ->subject($this->options['subject'])
  ->markdown('mail.invoice.paid', $this->options);

The second parameter in the markdown method is an array to pass into your view, through this you can include the various values you’d like to include in your email, such as contentParagraph1, greeting and salutation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading