Mastering the Modern Workflow: Exploring Laravel v8.62 Updates
Overview
Prerequisites
To get the most out of these features, you should have a solid grasp of
Key Libraries & Tools
- Laravel Forge: A server management tool for deploying and securing PHP applications.
- Pest: A community-driven testing framework focused on simplicity and elegant syntax.
- Eloquent ORM: The default database abstraction layer in Laravel for managing models.
Code Walkthrough: Fluent Input & Lazy Testing
Fluent Request Collections
Instead of wrapping request input in a manual helper, you can now retrieve inputs directly as a collection. This allows you to use powerful filtering and mapping methods immediately.
// The old way
$users = collect($request->input('users'))->filter(fn($u) => $u['score'] > 1000);
// The new fluent way
$users = $request->collect('users')->filter(fn($u) => $u['score'] > 1000);
Lazy Database Refreshing
Database refreshing often slows down test suites. The LazilyRefreshDatabase trait ensures the migration only runs if a specific test actually touches the database.
namespace Tests\Feature;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Tests\TestCase;
class UserTest extends TestCase
{
use LazilyRefreshDatabase;
// Database only resets if this test executes a query
public function test_user_creation() { ... }
}
Syntax Notes
Notice the use of the collect() method directly on the Request object. This follows the framework's movement toward Fluent Interfaces, where methods are chained to improve readability. Additionally, the new assertNotSoftDeleted() assertion complements the existing testing suite, providing a more semantic way to verify that a model has been restored or was never deleted.
Practical Examples
- Maintenance Hooks: Use the
MaintenanceModeEnabledevent to automatically pause external monitoring services likeOh Dear, preventing false downtime alerts during deployments. - Pest Integration: Generate Pestfiles directly via the CLI using
php artisan make:test UserTest --pestto quickly adopt the new testing standard.
Tips & Gotchas
When managing SSL via
