0
0
Laravelframework~30 mins

Mailable classes in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Creating a Simple Laravel Mailable Class
📖 Scenario: You are building a Laravel application that needs to send a welcome email to new users. To do this, you will create a Mailable class that holds the user's name and email content.
🎯 Goal: Build a Laravel Mailable class named WelcomeEmail that accepts a user's name, stores it, and sets up the email subject and view.
📋 What You'll Learn
Create a Mailable class named WelcomeEmail
Add a public property userName to hold the user's name
Create a constructor that accepts a $userName parameter and assigns it to the property
Set the email subject to 'Welcome to Our Platform!'
Use the view named emails.welcome for the email content
💡 Why This Matters
🌍 Real World
Mailable classes in Laravel help send emails with dynamic content, such as welcome messages, notifications, or password resets.
💼 Career
Understanding Mailable classes is essential for backend developers working with Laravel to implement email features in web applications.
Progress0 / 4 steps
1
Create the Mailable class with a public property
Create a Laravel Mailable class named WelcomeEmail that extends Illuminate\Mail\Mailable. Add a public property called userName to hold the user's name.
Laravel
Need a hint?

Remember to declare the property public $userName; inside the class.

2
Add the constructor to accept and assign the user name
Add a constructor method __construct to the WelcomeEmail class that accepts a parameter $userName and assigns it to the public property userName.
Laravel
Need a hint?

The constructor should assign the passed $userName to the class property $this->userName.

3
Set the email subject and view in the build method
Add a build method to the WelcomeEmail class that sets the email subject to 'Welcome to Our Platform!' and uses the view 'emails.welcome'.
Laravel
Need a hint?

The build method should return $this->subject(...)->view(...).

4
Complete the Mailable class with namespace and imports
Ensure the WelcomeEmail class has the correct namespace App\Mail and imports Illuminate\Mail\Mailable. The class should be fully ready to send emails with the user's name accessible in the view.
Laravel
Need a hint?

Check that the namespace and import statements are exactly as shown.