You can use the when()
or unless()
methods in your MailMessage notifications to set conditional object properties like a call to action.
1class InvoicePaid extends Notification 2{ 3 public function toMail(User $user) 4 { 5 return (new MailMessage) 6 ->success() 7 ->line('We've received your payment) 8 ->when($user->isOnMonthlyPaymentPlan(), function (MailMessage $message) { 9 $message->action('Save 20% by paying yearly', route('account.billing'));10 })11 ->line('Thank you for using Unlock.sh');12 }13}
Use the when
or unless
methods in you own classes by using the Illuminate\Support\Traits\Conditionable
trait
Tip given by @Philo01