0
0
Laravelframework~10 mins

Mailable classes 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 create a new mailable class using Artisan.

Laravel
php artisan make:[1] WelcomeEmail
Drag options to blanks, or click blank then click option'
Amiddleware
Bmodel
Ccontroller
Dmailable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'controller' instead of 'mailable' will create a controller, not an email class.
Using 'model' or 'middleware' creates unrelated classes.
2fill in blank
medium

Complete the code to send the mailable class named WelcomeEmail to a user.

Laravel
Mail::to($user->email)->[1](new WelcomeEmail());
Drag options to blanks, or click blank then click option'
Aqueue
Bsend
Cmake
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'queue' sends the email later, not immediately.
Using 'make' or 'create' are not valid methods for sending emails.
3fill in blank
hard

Fix the error in the build method to return the email view named 'emails.welcome'.

Laravel
public function build()
{
    return $this->[1]('emails.welcome');
}
Drag options to blanks, or click blank then click option'
Asend
Brender
Cview
Dmake
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' causes an error because it's not a method of the mailable class.
Using 'render' returns the HTML but does not set the email view.
4fill in blank
hard

Fill both blanks to pass data to the email view in the build method.

Laravel
public function build()
{
    return $this->view('emails.notification')->with([1] => [2]);
}
Drag options to blanks, or click blank then click option'
A'userName'
B$this->userName
C'email'
D$this->email
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without quotes for the key causes errors.
Passing wrong property names that don't exist in the class.
5fill in blank
hard

Fill all three blanks to define a constructor that accepts a User object and assigns it to a class property.

Laravel
public function __construct([1] $user)
{
    $this->[2] = [3];
}
Drag options to blanks, or click blank then click option'
AUser
Buser
C$user
DUserData
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class names or variable names.
Forgetting the dollar sign in the parameter variable.