Back to all funny docs

The Incredible Journey of Email Verification! 🚀📧

Warning: May cause actual learning AND laughter!

The Incredible Journey of Email Verification! 🚀📧

Get ready to embark on an epic adventure through the magical land of account verification! 🎉🌈

Prepping Your Model (Our Brave Knight) 🛡️

Before setting off, make sure your model is well-equipped with all the necessary email verification traits. Don’t forget to arm it with a verified_email field! ⚔️📝

Setting Up the Kingdom (Database) 🏰🗺️

Now that your model is prepared, let’s lay out our kingdom’s infrastructure. Create a verified_emails table and all its glorious columns to keep track of our verification statuses! 👑🗝️

The Royal Route (Routing) 🚦🏰

Navigate through the winding roads of routing, where we’ll establish several essential stops along the way.

The Verification Notice Post Office 📣🗞️

Our first stop is at the post office, where we’ll compose and send out the initial verification emails to our subjects! 💌🔥

The Verification Handler (The Royal Court) 🏰✍️

Next, let’s head over to the royal court, where our brave knights will handle the verification requests received from all corners of the land. 🛡️👑

Resending the Misplaced Letter (Email) 📧🔍

In case a letter gets lost in transit, we’ll need to implement a system for resending those emails with a friendly reminder! 📮😱

Protecting Our Castle from Intruders (Protecting Routes) 🛡️🏯

Lastly, let’s fortify our castle walls by ensuring that only verified subjects can enter the realm of protected routes! 🏰🔐

Customizing Our Kingdom (Customization) 🎨👑

Once we’ve established the foundations, let’s make our kingdom truly unique by customizing every little detail to our liking! 🎨💅

Announcing Royal Happenings (Events) 📢🏰

Last but not least, let’s celebrate the joyous moments of email verification with events, complete with fanfare and fireworks! 🎉🎇

Let’s Get Verified, Shall We?

Attention all web adventurers! If you’ve ever found yourself in a pickle trying to wrangle your users’ emails like a digital wrasslin’ match, fear no more! Laravel, your friendly neighborhood super-library, is here to save the day with its email verification services. No need for repetitive strain injury when building each new app - we’ve got your back!

[!ATTN: BAMF ALERT] Ready to sprint past the competition? Get your cape flying with one of our Laravel application starter kits in a fresh Laravel app. These kits will whisk you off your feet, scaffolding an entire authentication system (including email verification, because we’re all about making life easier).

Now, let’s get our models ready for the big event! (No tuxedos required.)

Alright, let’s dive into the world of Laravel Model Prep-show! 🎯 Before we get our groove on, make sure your App\Models\User model is not shy and knows how to dance with the Illuminate\Contracts\Auth\MustVerifyEmail contract. Here’s a little jive it might want to learn:

<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;  // Don't be a wallflower, join the dance floor!
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;

    // ...
}

Once it’s learned this dance, newly registered users will receive an email invitation to join the party—an email containing a verification link. The best part? Laravel is the ultimate hype man, automatically registering the Illuminate\Auth\Listeners\SendEmailVerificationNotification listener for the Illuminate\Auth\Events\Registered event, ensuring your model gets all the attention it deserves! 🎉

If your application is more of a DIY project and you’re manually implementing registration instead of using one of our starter kits, don’t forget to dispatch the Illuminate\Auth\Events\Registered event after a user’s successful registration:

use Illuminate\Auth\Events\Registered;

event(new Registered($user));  // Send out those invitations!

Now, let’s get this party started! 🥳

Alrighty, let’s get our nerd on and dive into the world of Laravel Database Preparation!

First things first, it’s time to deck out your users table with some swanky new digs. This is where we add an email_verified_at column—a chic little place to store the exact moment that one of your users officially verified their email address. You can think of this as the “red carpet” or the “official welcome-to-the-party” of the digital world for your user.

Now, you might be wondering where this magical column comes from—worry not! Laravel’s default 0001_01_00_000001_create_users_table.php database migration is where it hangs out when it’s not making new friends in your database.

But wait, there’s more! The party doesn’t stop here—we’ve just stepped into the cocktail hour of our Laravel journey. Next up, we’ll learn about routing for email verification! (Cue confetti and champagne bottles popping open) 🎉🥳🍾

Just kidding, it’s not really that fancy—but it is pretty darn important. Let’s get this show on the road!

Ahoy there, intrepid Laravel coders! 🌴🐠 Let’s dive into the vibrant world of routing, shall we? 🌊🤿

First off, we need to create a route that serves as a friendly reminder to our users. You know, like when your mom tells you to put on a jacket before heading outside. In this case, it’s telling them to click the email verification link that Laravel sent them after they registered - it’s their gateway to becoming a fully-fledged member of our awesome community! 🎉🎊

Next up, we’ve got the route that will handle requests like a well-trained butler handling a high tea service. You know, graceful, efficient, and just a little bit snobby. This route is in charge when our users click the verification link in their email. It’ll take care of verifying their account, allowing them to join the ranks of the verified and respected! 🌐👑

Last but certainly not least, we need a route that will come to the rescue when users accidentally lose the first verification link. It’s like finding your car keys in the fridge - sometimes things just get misplaced, and you’ve got to have a backup plan! This route will send a new verification link to help our users get back on track. 🔑☕️

So there you have it, three routes that will guide our users through the email verification process like a well-choreographed dance. Now go forth and route with pride, dear developers! 💃🕺🌍💪

Alrighty then! Let’s get our virtual feathers all ruffled about email verification, shall we? 🦃

As we’ve chirped before, it’s pivotal to establish a route that’ll serve up a view asking your newly-registered user to peck on that email verification link they got from Laravel post-registration. This view is quite the peacock strut when users attempt to flutter about other parts of your app sans verified email address. Remember, this link will automatically be sent out like a digital carrier pigeon as long as your App\Models\User model dons the snazzy MustVerifyEmail interface:

Route::get('/email/verify', function () {
    return view('auth.verify-email');
})->middleware('auth')->name('verification.notice');

Now, mark this route down in your rolodex as verification.notice. It’s crucial that this name ain’t altered a bit since the verified middleware (which comes bundled with Laravel) will perform a clever little redirect to this route name if a user hasn’t verified their email address yet.

[!NOTE] When crafting your email verification process by hand, you’ll be expected to compose the contents of that very same verification notice view yourself. If you fancy some assistance with all things authentication and verification views, take a gander at our Laravel application starter kits.

Now, wasn’t that a bit more enjoyable? 😎 Let’s keep the web development party going!

Alrighty then! Let’s dive into the world of email verification in Laravel land. First off, we need to create a route that’ll handle those clicky-clicky moments when users confirm their emails by following the link we send ‘em. This magical route should be christened verification.verify and decked out with the auth and signed middlewares, much like a fancy ball gown at a regal soiree. Here’s the code to make it all happen:

use Illuminate\Foundation\Auth\EmailVerificationRequest;

Route::get('/email/verify/{id}/{hash}', function (EmailVerificationRequest $request) {
    $request->fulfill();

    return redirect('/home');
})->middleware(['auth', 'signed'])->name('verification.verify');

Now, take a gander at this route. You’ll notice we’re using an EmailVerificationRequest instead of the usual Illuminate\Http\Request – think of it like wearing a cape instead of a plain t-shirt to feel extra superhero-ish. The EmailVerificationRequest is a fancy form request that comes with Laravel, making it an automatic validator for the id and hash parameters in our request.

Next up, we call the fulfill method on the request, which is like pressing the big ol’ “Verify Email” button in your email client (but more technical). This method takes care of marking the user’s email as verified and dispatches an Illuminate\Auth\Events\Verified event – perfect for all your celebratory email-verification needs. The markEmailAsVerified method is available to the default App\Models\User model via the Illuminate\Foundation\Auth\User base class. Once the user’s email address has been verified, you can send ‘em off to any ol’ destination you fancy.

Now, let’s say our users are a bit forgetful and need another chance at verifying their emails. We can create a helper function for sending the verification email again:

use Illuminate\Support\Facades\URL;

function sendVerificationEmail($user) {
    $verificationUrl = URL::temporarySignedRoute(
        'verification.verify', now()->addMinutes(60), [
            'id' => $user->getEmailForVerification(),
            'hash' => sha1($user->getEmailForVerification()),
        ]
    );

    // ... Send the email here with the verification url
}

This function generates a new verification URL for the user, which they can click to verify their email. The URL is time-limited and secure, thanks to being signed and hashed. You’ll want to plug this function into your registration or forgotten password process – just make sure to send the user on an exciting email journey!

Re-sending the Lost-in-Space Verification Email

Whoopsy daisies! Ever found yourself in a pickle when your user’s verification email went rogue on its intergalactic journey? Fear not, dear coder friend, for we have a cosmic solution to this celestial conundrum. To help our space-lost users hail their verification emails back home, you can set up a stargate (route) for them to request a reboot:

Use your phaser on 'stun' and import Illuminate\Http\Request;

Route::post('/alien_emails/recall', function (Request $request) {
    $request->user()->sendAlienEmailVerificationNotification();

    return back()->with('message', 'Verification beacon activated!');
})->middleware(['auth', 'throttle:6,1'])->name('verification.beacon');

Now, just hide this “request re-send” button in your extra-terrestrial verification notice view to keep the surprise until it’s needed for an emergency interstellar rescue mission.

Securing Your Routes Like a Fort Knox for Pigeons!

Ah, the sweet sound of digital security! Welcome to Laravel’s Route Middleware, where we protect our routes from unverified users - think of it as a bouncer at the hottest club in town.

But instead of a velvet rope, we use something called a verified middleware alias, which is just a fancy way of saying “That’s right, pal! Show us your verification email!” The best part? Laravel has already registered this bouncer for you, so all you need to do is slap on the wristbands (attach the middleware).

Here’s how you do it:

Route::get('/profile', function () {
    // Only verified users with a valid membership bracelet may enter...
})->middleware(['auth', 'verified']);

Now, if an unverified user tries to crash the party (access a route), they’ll be politely escorted to the verification.notice route - think of it as the line outside the club, waiting for their verification email.

And hey, you can even customize this bouncer! If you want to change the music or the drink prices, well… Laravel’s got your back with named routes. Just remember, it’s all about keeping the club (your application) secure and the tunes bumpin’! 🥳🚀🎉

Ahoy there, code swashbucklers! If you’re feeling a tad adventurous and want to personalize your Laravel ship, this section is right up your alley. Let’s dive in, shall we? 🌊🐬

Verification Email Customization

Ah, the thrill of sending out a beautifully crafted verification email that makes the recipient say “Wow, this Laravel pirate really knows how to code!” Let’s hoist the mainmast and set sail on customizing your verification emails. 🏴‍☠️

  1. Create a new view: You can create a new blade file in the emails directory, giving it the name of the email you want to customize (e.g., verify for the welcome email).
php artisan make:mail verify
  1. Edit the newly created file: Now that you have your very own verification email template, feel free to tinker with it to your heart’s content. Don’t forget to use Laravel’s built-in helper functions like trans($key) and url($url).

  2. Set the view for the welcome email: Open up your AppServiceProvider class and let’s point the welcome email towards its newly customized destination by updating the sendVerificationEmail method:

use Illuminate\Support\Facades\Mail;

// ...
public function boot()
{
    $this->app->booted(function () {
        if ($this->app->environment('local', 'testing')) {
            event(new \Illuminate\Queue\Events\Queued($this->app['queue']));
        }

        Mail::send(['html' => 'emails.verify'], $data, function ($message) {
            // Customize your email here! 🎨
        });
    });
}

Now, the next time a user signs up for your Laravel treasure hunt, they’ll be greeted with an email that is nothing short of a masterpiece. 🎉

Remember, customization is like adding a parrot on your shoulder – it makes you stand out from the rest! So, grab your compass and set sail towards even greater adventures in Laravel land. Arr matey! ROT 🏴‍☠️

Ahoy there, code pirates! 🌴🌊 If you’re here, it means you’ve taken the plunge into Laravel waters and are ready to customize that email verification shanty of yours. 🎺📧

By default, our shipshape emails should be enough to make Davy Jones himself click ‘verify’, but if ye hanker for more, Laravel lets you refit the cannons (email notifications) to your heart’s desire! 🐳🌮

To embark on this customization voyage, hoist the sail and pass a ‘closure’ matey, to the toMailUsing method, provided by the Illuminate\Auth\Notifications\VerifyEmail notification. This closure will accept two arguments: the notifiable model instance that’s about to get its inbox flooded, and the signed email verification URL the user must navigate to verify their email address. The closure should eventually return an instance of Illuminate\Notifications\Messages\MailMessage.

You’ll want to set sail from the boot method of your application’s AppServiceProvider class:

use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Notifications\Messages\MailMessage;

/**
 * Shake the ship's rigging and wake up the crew.
 */
public function boot(): void
{
    // ...

    VerifyEmail::toMailUsing(function (object $notifiable, string $url) {
        return (new MailMessage)
            ->subject('Yo Ho, Verify Yonder Email Address')
            ->line('Arrr, click this button below to verify yer email address.')
            ->action('Verify Email Address', $url);
    });
}

[!NOTE] If ye want more tales of the sea (mail notifications), hoist the Jolly Roger and head over to the mail notification documentation. 🏴‍☠️⚓️

Alright, listen up, tech-savvy cowpokes! Let’s gallop into the wild world of Laravel Events, shall we?

When you’re corralling those app ponies with our handy starter kits (available at /docs/{{version}}/starter-kits), Laravel saddles up and fires off an Illuminate\Auth\Events\Verified event during the email verification rodeo. Now, if you’re handling your own wrangling of emails for your application, you might find yourself hankering to manually unleash these events after the lassoing is done.

So, put on your ten-gallon hat and let’s get this roundup started! If you’re itchin’ to learn more about Laravel Events, you can head over to /docs/{{version}}/events for some educational horseback riding. Yeehaw! 🤠🐎🌵

Other Funny Docs

**Welcome to Laravel Land!** 🌄 # Collections 🎉🎩 # Concurrent Chaos, or How to Make Your Computer Dance Simultaneously 🕺️💃️ # Controllers: The Gladiators of the Digital Colosseum 🏆 # Database: The Magical Scroll of Infinite Data! 🧙‍♂️📖 # Eloquent: The Great Serialize-Off! 🥳🎉 # Eloquent: The Swanky Buffet of Data! 🎉🍽️ # Eloquent's Amorous Affairs: A Love Letter to Data Relations! # Hashbash 101: Laravel's Secret Sauce for Security! 🔒🎉 # Laravel's Heart Monitor 💼🕺️ # Laravel's Magical Deployment Genie: Envoy! 🧞‍♂️🎩 # Laughter Logs 😃 # Locksmith Services: Laravel's Top-Secret Spy Kit 🔑🕵️‍♂️ # The Database Dance: A Laravel Ballroom Guide 💃🏻🎉 # The Grand Ol' Setup! 🎶🥁 # The Great File Adventure! 📚 🚀 # The Great Laravel Password Adventure # The Magnificent Mongoose's Guide to Storing Data in the Land of BSON! 🦁📜 🔔📣 **Attention All Developers!** A Journey Through Laravel's File System Jungle! 🌳🔍 Ahoy there, coders and jesters alike! Brace yourself for a thrilling journey through the fantastical realm of Laravel Strings - the magic ingredient that makes your apps talk to you like a wise old sage (or a chatty parrot, if you prefer). Ahoy there, database enthusiasts! Let's embark on a fantastical journey into the heart of Laravel's mystifying seed land! Yes, you heard it right – we're talking about Database Seeding! Ahoy there, intrepid coder! Set sail for a grand adventure with Laravel's swashbuckling documentation! 🏴‍☠️ Ahoy there, Laravel sailors! Buckle up for an exhilarating journey into the realm of Eloquent API Resources. This section is chock-full of goodies that'll make your RESTful dreams come true. Let's dive right in! 🌊 Ahoy there, matey! Buckle up for a whirlwind tour of Laravel's process management! This is where the magic happens, and by "magic," we mean command line sorcery. Ahoy, mateys! Sail the Laravel seas with us as we delve into the art of mockery - not the kind that makes people laugh (although that's always a plus), but the one that helps you write better tests. Ready to plunder treasures of knowledge? Let's set sail! Alright, let's dive into the hilarious world of Laravel Licensing! 🎠🎪 Alrighty, buckle up, coding cowboy (or cowgirl)! Let's dive into the wild west of Laravel deployment where we'll tame servers, tweak configurations, and optimize for speedier draw times. But first, a quick warning: this here is more than just roping cattle, so if you ain't familiar with server requirements, Nginx, FrankenPHP, or directory permissions, best hitch a ride on the documentation horse. Anchors Aweigh! Welcome to Laravel Sail! 🚢🚀 Console Chortles: The Laugh-and-Learn Guide 🎤️ Contracts: The Sworn Code of Laravel Land! 🤝📜 Database: The Gateway to Data Nirvana 🚀🌟 Database: The Quarry Master Database: Time Machine for Your Data Eloquent: The Magic of Mutators & Casting! 🎩✨ Eloquent: The Magical Factory of Your Database Dreams! 🧚‍♂️🛠️ Eloquent: The Posh Puppy of PHP Database Frameworks! 🐶 Fancy Pants Shortcuts 🤵👗 Frontend Fun Times! 🎉🎈 HTTP Hooligans: A Survival Guide for Web Shenanigans in Laravel Land! 🤓 Laravel Cashier (Paddle): The Silicon Valley of Subscription Billing 🚀✨ Laravel Cashier: Your Buddy for Stripe Shenanigans! 💰💳 Laravel Dusk: The Web Browser Robot for Your Laravel App! 🤖 Laravel Flagship 🏳️‍🌈 Laravel Forti-Fantastic! 🎉🏰 Laravel Mix: The Magical Elixir of Your Web Application's Happiness 🍰 Laravel Octane: The Supercharged PHP Superhero! ⚡️🚀 Laravel Passport: The Magic Key to Your API Kingdom 🔑✨ Laravel Pint: Your Chill Buddy for Code Quality! 🍻 Laravel Sanctum: Your Secret Weapon for API Security! 🚀🛡️ Laravel Scout: The Sherlock of Databases! 🕵️‍♂️ Laravel's AI Sidekick 🚀🤖 Laravel's AI Time Machine 🕰️🚀 Laravel's Bag O' Tricks! Laravel's Dance Floor: A Symphony of Code! 🎶🥁 Laravel's Magical Command-Line Puppeteer (MCP) ✨🎩 Laravel's Magical Domain Whisperer: Valet! 🧙‍♂️🔮 Laravel's Magical Homestead for Developers, Wizards, and Aliens! 🏡🚀 Laravel's Magical, Shiny Socialite! 🌈✨ Laravel's Shining Star: Horizon! 🚀✨ Laravel's Stargazing Gadget: Telescope! 🔭🚀 Laravel's Swanky Navigation Guide! 🕺️ Laugh, Log, Love! 🤖 logging in Laravel 🎉 Laugh, Test, Conquer: Your Laravel Guide to Fun-tastic Testing! 🥳🎉 Laughable Laravel HTTP Hilarity! 🎭💬 Laughing at the Glitches: Laravel's Error Handling Guide! 😜 Laughter and Coding: A Journey to Laravel 13.0! (From the Stables of 12.x) Let's Chat Like Never Before with Laravel Broadcasting! 🗣️🎙️ Lingo-Magic: Make Your Laravel App Speak Every Language Under the Sun! 🌍🎙️ Middleware Mayhem! 🕹️🦸‍♂️ Package Shenanigans! 🎉🥳 Redis: The Swift, Silicon Superhero of Data Storage! 🦸‍♂️🚀 Rockstar Rate Limiting 🎸🥁🎉 Service Provider Shenanigans! 🤘 Temples of Data: Laravel's Views Temple (Don't worry, no incense required) The All-Knowing, Magic Bean of PHP Land! 🪄🚀 The Art of Email in Laravel Land! 🕵️‍♂️💌 The Art of Validation: A Laravel Masterclass! 🎉🎓 The Artisan's Playground 🧛‍♂️🔩 The Dance of Responses The Gatekeeper's Handbook (But Slightly More Entertaining) The Globetrotter's Guide to Laravel Sessions The Great Escape Act: Laravel's Magic Trick with Queues! The Great Interweb Explorer: Laravel's HTTP Client The Great Laravel Journey: A Comic Adventure! 🎉🚀 The Great Laravel Soiree: An Eventful Revelry! 🎉🎊 The Incredible, Mysterious World of CSRF Protection! 🦹‍♂️🔒 The Joyful Symphony of Asset Bundling: Vite Edition! 🎶 The Laravel Play-Doh Kit: Your Gateway to Fun and Fancy Web Development! 🎨🌐 The Magic Show of Laravel Lifecycle 🎩✨ The Quest for Knowledge: A Laravel Adventure! 📚🚀 The Time Travelling Task Manager (TTTM) The Wild West of Web Navigation: Laravel's Routing! 🤠🎠 Time Travel, Laravel Style! 🔮⏳ Title: **How to Contribute Like a Rockstar 🎸** Title: **Welcome to Laravel's Magical Terminal Tour!** 🎪🎧 Unleash the Power of Cache! (Or, How to Speed Up Your App Without Breaking a Sweat) Unlocking the Kingdom! (aka, Authentication in Laravel) URL Navigation: The Cosmic Wayfarer's Guide to Cyberspace! 🛸🚀 Welcome to Laravel Boost, the supercharger for your PHP applications! 🚀💨 Welcome to Laravel Land! 🌴🎉 Wickedly Wonderful Blade Templates! 🧙‍♂️🔮