0
0
Laravelframework~10 mins

Why notifications reach users effectively in Laravel - Test Your Understanding

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

Complete the code to send a notification to a user in Laravel.

Laravel
use App\Notifications\InvoicePaid;

$user->[1](new InvoicePaid($invoice));
Drag options to blanks, or click blank then click option'
Anotify
Balert
CsendNotification
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like sendNotification or alert which do not exist on the user model.
Trying to call notification methods directly without using the notify method.
2fill in blank
medium

Complete the code to define the notification channels in Laravel.

Laravel
public function via($notifiable)
{
    return [[1]];
}
Drag options to blanks, or click blank then click option'
A'mail', 'database'
B['sms', 'push']
C['mail', 'database']
D'sms', 'push'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a string with commas instead of an array.
Using single quotes without brackets which causes errors.
3fill in blank
hard

Fix the error in the notification class to send an email notification.

Laravel
public function toMail($notifiable)
{
    return (new MailMessage)
        ->subject('Invoice Paid')
        ->[1]('Your invoice has been paid successfully.');
}
Drag options to blanks, or click blank then click option'
Aline
Bmessage
Ccontent
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using message or content which are not valid methods on MailMessage.
Trying to use text which does not exist.
4fill in blank
hard

Fill both blanks to store notification data in the database.

Laravel
public function toDatabase($notifiable)
{
    return [
        'invoice_id' => [1],
        'amount' => [2]
    ];
}
Drag options to blanks, or click blank then click option'
A$this->invoice->id
B$this->invoice->total
C$this->invoice->amount
D$this->invoice->number
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names like amount instead of total.
Mixing invoice number with invoice id.
5fill in blank
hard

Fill all three blanks to customize the notification's broadcast message.

Laravel
public function toBroadcast($notifiable)
{
    return new BroadcastMessage([
        'invoice_id' => [1],
        'status' => [2],
        'message' => [3]
    ]);
}
Drag options to blanks, or click blank then click option'
A$this->invoice->id
B'paid'
C'Your invoice has been paid successfully.'
D$this->invoice->status
Attempts:
3 left
💡 Hint
Common Mistakes
Using hardcoded status string instead of the invoice status property.
Putting the message in the wrong blank.