Only until Jan 16th: coupon RESOLUTION25 for 40% off Yearly/Lifetime membership!

Read more here

Set conditional object properties

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

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 69 courses (1205 lessons, total 45 h 02 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses