0
0
Laravelframework~10 mins

Creating notifications in Laravel - Interactive Practice

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

Complete the code to create a new notification class using Artisan.

Laravel
php artisan [1] NotificationName
Drag options to blanks, or click blank then click option'
Anew:notification
Bmake:notification
Cgenerate:notification
Dcreate:notification
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create:notification' instead of 'make:notification'.
Forgetting to include the notification name after the command.
2fill in blank
medium

Complete the code to send a notification to a user instance.

Laravel
$user->[1](new InvoicePaidNotification($invoice));
Drag options to blanks, or click blank then click option'
AnotifyAll
Balert
CsendNotification
Dnotify
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'notifyAll' which does not exist on the user model.
Using 'sendNotification' which is not a Laravel method.
3fill in blank
hard

Fix the error in the notification class to specify the delivery channels.

Laravel
public function [1](mixed $notifiable): array
{
    return ['mail', 'database'];
}
Drag options to blanks, or click blank then click option'
Avia
Bsend
Cchannels
Ddeliver
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' or 'deliver' which are not valid method names for channels.
Using 'channels' which is not the correct method name.
4fill in blank
hard

Fill both blanks to return the mail message with a subject and greeting.

Laravel
public function toMail(mixed $notifiable): MailMessage
{
    return (new MailMessage)
        ->subject([1])
        ->greeting([2]);
}
Drag options to blanks, or click blank then click option'
A'Invoice Paid'
B'Hello!'
C'Welcome'
D'Your invoice has been paid'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up subject and greeting strings.
Using variables instead of strings.
5fill in blank
hard

Fill all three blanks to create a database notification array with an invoice id, amount, and status.

Laravel
public function toDatabase(mixed $notifiable): array
{
    return [
        'invoice_id' => [1],
        'amount' => [2],
        'status' => [3]
    ];
}
Drag options to blanks, or click blank then click option'
A$this->invoice->id
B$this->invoice->amount
C'paid'
D'pending'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names or missing the $this keyword.
Using 'pending' instead of 'paid' for status.