Overview Laravel v8.78 introduces significant ergonomic improvements to the framework, focusing on memory efficiency, database schema flexibility, and a more expressive syntax for Eloquent models. These updates streamline common developer tasks, from handling massive datasets to defining model attributes with less boilerplate code. Prerequisites To follow this guide, you should be comfortable with PHP and basic Laravel concepts like Migrations and Eloquent models. Familiarity with Carbon for date manipulation and basic MySQL or PostgreSQL indexing is helpful. Key Libraries & Tools - Laravel v8.78: The core framework version featuring these updates. - Eloquent ORM: The database abstraction layer receiving new attribute syntax. - Carbon: The standard library for date and time handling in Laravel. - Laravel Forge: A server management tool that recently underwent a complete UI overhaul using Vue.js and Tailwind CSS. Code Walkthrough Memory-Efficient Lazy Loading Laravel now provides a `lazyByIdDesc` method to handle large datasets in reverse order while maintaining a low memory footprint. ```python $flights = Flight::where('departed', true) ->lazyByIdDesc(100); foreach ($flights as $flight) { // Processes 100 records at a time } ``` Unified Accessors and Mutators Taylor Otwell introduced a streamlined way to define model logic. Instead of two separate methods, you define one method returning an `Attribute` object. ```python use Illuminate\Database\Eloquent\Casts\Attribute; protected function name(): Attribute { return Attribute::make( get: fn ($value) => ucwords($value), set: fn ($value) => strtolower($value), ); } ``` Request Date Integration You can now cast incoming request data directly to Carbon instances using the `date` method, eliminating manual instantiation. ```python $expiryDate = $request->date('expires_at', 'Y-m-d', 'UTC'); ``` Syntax Notes The new `Attribute` return type is a non-breaking change. Laravel only treats a method as an accessor/mutator if it explicitly declares the `Attribute` return type. This prevents conflicts with existing methods that might share attribute names. Practical Examples - **Security Gates**: Use `Gate::allowIf(fn() => $user->isPremium())` for cleaner authorization logic. - **Search Optimization**: Apply `$table->fullText('bio')` in migrations to enable advanced searching in MySQL. - **Privacy**: Use the `invisible` modifier on sensitive database columns to prevent them from appearing in `SELECT *` results. Tips & Gotchas When using the new `schedule:clear-cache` command, remember it specifically targets mutex files. This is a lifesaver when a server reboot leaves a scheduled task "locked," but it won't fix logic errors within the task itself. Always ensure your migration targets MySQL 8.0.23+ if you plan to use the `invisible` column modifier.
Tailwind CSS
Libraries
Jan 2022 • 1 videos
High activity month for Tailwind CSS. Laravel among the most active voices, with 1 videos across 1 sources.
Jan 2022
- Jan 10, 2022