Laravel Feature Deep Dive: WhereLike, Advanced Mail Assertions, and Microsecond Time Travel

Laravel////2 min read

Overview

Modern application development demands both developer velocity and code clarity. The latest updates to the framework (v11.16 & 11.17) focus on reducing boilerplate in database queries, simplifying mail testing, and introducing high-precision time manipulation. These features allow developers to write more expressive code that mirrors natural language.

Prerequisites

To follow this guide, you should be comfortable with syntax and have a basic understanding of the ORM. Familiarity with or for testing is recommended.

Key Libraries & Tools

  • : The primary PHP framework used for web development.
  • : Laravel's built-in ORM for database interactions.
  • : The library powering Laravel's time manipulation features.

Fluent Database Queries with WhereLike

Traditionally, performing a partial match in required passing the like operator as a string argument. While functional, it felt clunky.

// The old way
$podcasts = Podcast::where('title', 'like', '%Laravel%')->get();

// The new fluent way
$podcasts = Podcast::whereLike('title', '%Laravel%')->get();

This update includes whereNotLike, orWhereLike, and orWhereNotLike. It abstracts the underlying SQL, ensuring consistent behavior across and without manual operator injection.

Streamlined Mail Testing

Testing that an email reached the correct recipient used to require a closure and a manual boolean check within Mail::assertSent. You can now pass the recipient's email directly as the second argument.

// Before: Verbose closure
Mail::assertSent(PodcastPublished::class, function ($mail) use ($user) {
    return $mail->hasTo($user->email);
});

// After: Direct assertion
Mail::assertSent(PodcastPublished::class, $user->email);

You can also pass an array of emails if you expect multiple recipients, making your test suite significantly more readable.

High-Precision Time Travel

While travel(10)->seconds() is common for testing expires_at logic, high-frequency systems like trading platforms or benchmarking tools require finer control. now supports microsecond precision.

// Travel and freeze for precision
$this->freezeTime();
$this->travel(10)->microseconds();

$this->get('/podcast')
     ->assertSee('created 10 microseconds ago');

Tips & Gotchas

When testing microseconds, always use freezeTime(). Without it, the few milliseconds it takes for the CPU to execute the next line of code will cause your assertion to fail because the system clock continues to tick.

Topic DensityMention share of the most discussed topics 路 12 mentions across 8 distinct topics
25%software
25%software
8%software
8%software
8%software
Other topics
25%
End of Article
Source video
Laravel Feature Deep Dive: WhereLike, Advanced Mail Assertions, and Microsecond Time Travel

Microsecond Travel, Assert Sent To & Where Like

Watch

Laravel // 7:13

The official YouTube channel of Laravel, the clean stack for Artisans and agents. We will update you on what's new in the world of Laravel, from the framework to our products Cloud, Forge, and Nightwatch.

Who and what they mention most
2 min read0%
2 min read