0
0
Laravelframework~10 mins

Notification channels (mail, database, SMS) in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send a mail notification using Laravel's Notification system.

Laravel
Notification::route('mail', 'user@example.com')->[1](new InvoicePaid($invoice));
Drag options to blanks, or click blank then click option'
Adispatch
Bsend
Cnotify
Dalert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' instead of 'notify'
Using 'dispatch' which is for jobs
Using 'alert' which is not a Laravel method
2fill in blank
medium

Complete the code to define the database notification channel in the notification class.

Laravel
public function via($notifiable)
{
    return ['[1]'];
}
Drag options to blanks, or click blank then click option'
Adatabase
Bsms
Cmail
Dbroadcast
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sms' or 'mail' instead of 'database'
Using 'broadcast' which sends real-time notifications
3fill in blank
hard

Fix the error in the SMS notification method to return the correct message format.

Laravel
public function toSms($notifiable)
{
    return (new SmsMessage)
        ->content('[1]');
}
Drag options to blanks, or click blank then click option'
AYour invoice has been paid.
B'Your invoice has been paid.'
C['Your invoice has been paid.']
Dcontent('Your invoice has been paid.')
Attempts:
3 left
💡 Hint
Common Mistakes
Adding extra quotes around the message
Passing message as an array
Calling content inside content
4fill in blank
hard

Fill both blanks to create a database notification with a custom data array.

Laravel
public function toArray($notifiable)
{
    return [
        '[1]' => $this->invoice->id,
        '[2]' => $this->invoice->amount,
    ];
}
Drag options to blanks, or click blank then click option'
Ainvoice_id
Binvoice_number
Camount
Dtotal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'invoice_number' instead of 'invoice_id'
Using 'total' instead of 'amount'
5fill in blank
hard

Fill all three blanks to send a notification via mail, database, and SMS channels.

Laravel
public function via($notifiable)
{
    return ['[1]', '[2]', '[3]'];
}
Drag options to blanks, or click blank then click option'
Amail
Bdatabase
Csms
Dbroadcast
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'broadcast' instead of 'sms'
Missing one of the required channels