Modernizing Your Stack with Laravel 8.70: Enums and Enhanced Scoping

Laravel////3 min read

Overview

Laravel 8.70 represents a pivotal update focusing on developer ergonomics and forward compatibility with PHP 8.1. 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 Laravel 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 Enums. 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 PHP 8.1 users, check your log channels; deprecation notices are now logged by default instead of stopping execution, which helps with smoother runtime migrations.

Topic DensityMention share of the most discussed topics · 12 mentions across 7 distinct topics
PHP 8.1
33%· languages
Enums
17%· software
Laravel
17%· software
Laravel Vapor
8%· software
MySQL 8
8%· software
Other topics
17%
End of Article
Source video
Modernizing Your Stack with Laravel 8.70: Enums and Enhanced Scoping

What's New in Laravel 8.70

Watch

Laravel // 9:56

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.

3 min read0%
3 min read