PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, April 19, 2022

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

 April 19, 2022     email, laravel, notifications, php     No comments   

Issue

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:

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.



Answered By - Bilal sagheer Awan
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing