You can use the when() or unless() methods in your MailMessage notifications to set conditional object properties like a call to action.
class InvoicePaid extends Notification{ public function toMail(User $user) { return (new MailMessage) ->success() ->line('We\'ve received your payment') ->when($user->isOnMonthlyPaymentPlan(), function (MailMessage $message) { $message->action('Save 20% by paying yearly', route('account.billing')); }) ->line('Thank you for using Unlock.sh'); }}
Use the when or unless methods in you own classes by using the Illuminate\Support\Traits\Conditionable trait
Tip given by @Philo01
Enjoyed This Tip?
Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.
Recent Courses
Laravel Coding with AI Agents: Cursor, Claude Code, Codex
5 lessons
1 h 01 min
Filament 4 From Scratch
28 lessons
2 h 25 min
PhpStorm Junie AI for Laravel Projects: Crash Course
7 lessons
36 min