Modernizing Your Stack with Laravel 8.70: Enums and Enhanced Scoping

Overview

Laravel 8.70 represents a pivotal update focusing on developer ergonomics and forward compatibility with

. This release simplifies complex validation logic and introduces deep integration for native
Enums
, which fundamentally changes how we handle static data sets in our models and database queries. It addresses common pain points in route scoping and middleware management, making the framework more expressive and less verbose.

Prerequisites

To follow this guide, you should have a solid grasp of

fundamentals, particularly Eloquent models and routing. Familiarity with
PHP
type hinting is recommended. For Enum-specific features,
PHP 8.1
is required.

Key Libraries & Tools

  • Laravel
    : The primary PHP framework providing these updates.
  • PHP 8.1
    : The runtime required for native Enum support and modern exception handling.
  • Laravel Vapor
    : A serverless deployment platform now supporting RDS proxies for
    MySQL 8
    .

Native Enum Integration

One of the most powerful updates is the ability to cast model attributes directly to

. This eliminates the need for manual string comparisons and ensures data integrity at the code level.

// In your Model
protected $casts = [
    'status' => StatusEnum::class,
];

// Usage in queries
$services = Service::where('status', StatusEnum::Done)->get();

Laravel handles the serialization behind the scenes, converting the Enum case to its backed value (string or integer) before it hits the database. This pattern makes your business logic significantly more readable and less prone to typos.

Advanced Route Scoping

Previously, scoping child models in a route required custom keys. The new scopeBindings() method automates this process using your Eloquent relationships.

Route::get('/users/{user}/servers/{server}', function (User $user, Server $server) {
    return $server;
})->scopeBindings();

This ensures the {server} must belong to the {user}. If the relationship doesn't exist, Laravel automatically returns a 404, saving you from writing manual ownership checks in your controllers.

Syntax Notes

  • Declined Rule: Use declined for negative boolean logic (e.g., verifying a user checked "No" for a criminal record).
  • Multiple Date Formats: The date_format rule now accepts comma-separated strings (e.g., date_format:Y-m-d,d/m/Y).
  • Middleware Exclusion: Use withoutMiddleware() to punch holes in group-level security for specific endpoints like public help pages.

Tips & Gotchas

Always define your Eloquent relationships before using scopeBindings(). If the relationship is missing, the framework will throw an exception rather than a 404. For

users, check your log channels; deprecation notices are now logged by default instead of stopping execution, which helps with smoother runtime migrations.

3 min read