0
0
Laravelframework~30 mins

Email verification in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Email verification
📖 Scenario: You are building a simple Laravel application that requires users to verify their email addresses after registration. This helps ensure that users provide valid emails before accessing protected parts of the app.
🎯 Goal: Create a Laravel controller and routes to handle sending email verification links and verifying users when they click the link.
📋 What You'll Learn
Create a controller named EmailVerificationController
Add a route to send the email verification notification
Add a route to verify the email using a signed URL
Use Laravel's built-in email verification features
💡 Why This Matters
🌍 Real World
Email verification is essential in real apps to confirm user identity and reduce fake accounts.
💼 Career
Understanding Laravel's email verification helps you build secure user authentication flows, a common requirement in web development jobs.
Progress0 / 4 steps
1
Create EmailVerificationController
Create a controller named EmailVerificationController inside app/Http/Controllers with a method sendVerificationEmail that accepts a Request parameter.
Laravel
Need a hint?

Use Auth::user() to get the logged-in user and call sendEmailVerificationNotification() on it.

2
Add route to send verification email
Add a POST route in routes/web.php with URL /email/send-verification that uses EmailVerificationController@sendVerificationEmail and applies the auth middleware.
Laravel
Need a hint?

Use Route::post with the URL and controller method, then chain middleware('auth').

3
Add route for email verification link
Add a GET route in routes/web.php with URL /email/verify/{id}/{hash} that uses VerificationController@verify and applies the auth and signed middleware.
Laravel
Need a hint?

Use Route::get with the URL and controller method, add auth and signed middleware, and name the route verification.verify.

4
Create VerificationController with verify method
Create a controller named VerificationController inside app/Http/Controllers with a method verify that accepts Request $request. Inside, call $request->user()->markEmailAsVerified() and return a JSON response with message 'Email verified successfully.'.
Laravel
Need a hint?

Use markEmailAsVerified() on the authenticated user and return a JSON message.