Back to Laravel Meetup Stockholm

Laravel Tips & Tricks

Complete collection of Laravel ecosystem best practices, featuring the latest in Laravel 12, Filament 4, Inertia.js v2, and Pest 4

These facts are also featured in our interactive countdown at Laravel Meetup Stockholm events!

🚀Laravel 12 introduces new starter kits for React, Vue, and Livewire with modern tooling

Code Example

"color: #6B7280;">// Laravel 12 "color: #8B5CF6;">new starter kits
"color: #6B7280;">// Create a "color: #8B5CF6;">new React app with TypeScript & shadcn/ui
"color: #8B5CF6;">laravel "color: #8B5CF6;">new myapp --kit=react

"color: #6B7280;">// Create a "color: #8B5CF6;">new Vue app with "color: #8B5CF6;">Inertia v2
"color: #8B5CF6;">laravel "color: #8B5CF6;">new myapp --kit=vue

"color: #6B7280;">// Create a "color: #8B5CF6;">new Livewire app with Flux UI
"color: #8B5CF6;">laravel "color: #8B5CF6;">new myapp --kit=livewire

🔐Laravel 12 offers WorkOS AuthKit integration for advanced authentication features

Code Example

"color: #6B7280;">// Laravel 12 with WorkOS AuthKit
"color: #8B5CF6;">laravel "color: #8B5CF6;">new myapp --kit=react --auth=workos

"color: #6B7280;">// Includes social auth, passkeys, and SSO
"color: #6B7280;">// Free for up to 1 million monthly active users
"color: #8B5CF6;">Route::get('/login/google', [AuthController::"color: #8B5CF6;">class, 'redirectToGoogle']);
"color: #8B5CF6;">Route::get('/login/github', [AuthController::"color: #8B5CF6;">class, 'redirectToGithub']);

🔧Filament 4 features an automated upgrade script to handle most breaking changes

Code Example

"color: #6B7280;">// Filament 4 automated upgrade
"color: #8B5CF6;">composer require filament/upgrade:"^4.0" -W --dev

"color: #8B5CF6;">vendor/bin/filament-v4

"color: #6B7280;">// Handles most breaking changes automatically
"color: #8B5CF6;">composer require filament/filament:"^4.0" -W --no-update
"color: #8B5CF6;">composer update

📁Filament 4 introduces new directory structure for better organization

Code Example

"color: #6B7280;">// Filament 4 "color: #8B5CF6;">new directory structure
app/Filament/
├── Resources/
│   ├── UserResource/
│   │   ├── Pages/
│   │   └── RelationManagers/
│   └── UserResource."color: #8B5CF6;">php
└── Clusters/
    └── Settings/

Laravel 12 is a minimal breaking changes release focusing on dependency updates

Code Example

"color: #6B7280;">// Laravel 12 minimal breaking changes
"color: #6B7280;">// Most Laravel 11 apps can upgrade without code changes
"color: #8B5CF6;">composer require "color: #8B5CF6;">laravel/framework:"^12.0"

"color: #6B7280;">// Focus on quality-of-life improvements
"color: #6B7280;">// Upgraded upstream dependencies
"color: #6B7280;">// Maintained backward compatibility

📜Inertia.js v2 adds merging props with Inertia::merge() for seamless infinite scrolling

Code Example

"color: #6B7280;">// Merging props with "color: #8B5CF6;">Inertia v2
"color: #8B5CF6;">Route::get('/posts', "color: #8B5CF6;">function () {
    "color: #8B5CF6;">return "color: #8B5CF6;">Inertia::render('Posts', [
        'posts' => "color: #8B5CF6;">Inertia::merge($posts),
    ]);
});

🎭Pest 4 introduces browser testing with built-in visual regression testing capabilities

Code Example

"color: #6B7280;">// Visual regression testing with Pest 4
"color: #8B5CF6;">it('matches homepage design', "color: #8B5CF6;">function () {
    visit('/')->assertMatchesSnapshot();
});

🔒Laravel's 'once()' helper prevents duplicate execution of expensive operations

Code Example

"color: #6B7280;">// Prevent duplicate execution with once()
"color: #8B5CF6;">class ProcessOrder
{
    "color: #8B5CF6;">public "color: #8B5CF6;">function handle()
    {
        once("color: #8B5CF6;">function () {
            "color: #6B7280;">// This expensive operation will only run once
            "color: #8B5CF6;">return $this->calculateComplexMetrics();
        });
    }
}

🚀Filament 3's bulk actions can handle large datasets efficiently with chunked processing

Code Example

"color: #6B7280;">// Efficient bulk actions in Filament 3
BulkAction::make('archive')
    ->action("color: #8B5CF6;">function (Collection $records) {
        $records->chunk(1000)->each("color: #8B5CF6;">function ($chunk) {
            $chunk->each->archive();
        });
    });

Inertia.js v2 supports prefetching pages on hover for lightning-fast navigation

Code Example

"color: #6B7280;">// Prefetch on hover with "color: #8B5CF6;">Inertia v2
"/dashboard" prefetch="hover">
    Dashboard

🏃‍♂️Pest 4 can run tests in parallel across multiple processes, dramatically reducing test execution time

Code Example

"color: #6B7280;">// Parallel testing with Pest 4
./"color: #8B5CF6;">vendor/bin/pest --parallel --processes=8

"color: #6B7280;">// Or in pest."color: #8B5CF6;">php
"color: #8B5CF6;">uses()->parallel();

🧹Laravel 11 includes automatic model pruning for cleaning up old records

Code Example

"color: #6B7280;">// "color: #8B5CF6;">Model pruning in Laravel 11
"color: #8B5CF6;">class LogEntry extends "color: #8B5CF6;">Model
{
    "color: #8B5CF6;">use Prunable;

    "color: #8B5CF6;">public "color: #8B5CF6;">function prunable()
    {
        "color: #8B5CF6;">return "color: #8B5CF6;">static::"color: #8B5CF6;">where('created_at', '<=', now()->subMonth());
    }
}

Filament 3 supports real-time form validation with live() method

Code Example

"color: #6B7280;">// Real-time validation in Filament 3
TextInput::make('email')
    ->email()
    ->live(onBlur: true)
    ->afterStateUpdated(fn ($state, $set) =>
        $set('email_verified', User::"color: #8B5CF6;">where('email', $state)->exists())
    );

🛡️Inertia.js v2 introduces automatic error boundary handling for better user experience

Code Example

"color: #6B7280;">// Error boundaries in "color: #8B5CF6;">Inertia v2
import { ErrorBoundary } from '@inertiajs/react'

Something went wrong!
} onError={(error) => console.error(error)} >

📊Pest 4's dataset feature allows testing multiple scenarios with clean syntax

Code Example

"color: #6B7280;">// Datasets in Pest 4
"color: #8B5CF6;">it('validates email formats', "color: #8B5CF6;">function ($email, $expected) {
    "color: #8B5CF6;">expect(filter_var($email, FILTER_VALIDATE_EMAIL))
        ->toBe($expected);
})->with([
    ['valid@email.com', true],
    ['invalid-email', false],
]);

🎯Laravel 11's query builder can prevent N+1 queries with lazy loading detection

Code Example

"color: #6B7280;">// N+1 prevention in Laravel 11
"color: #6B7280;">// In AppServiceProvider
"color: #8B5CF6;">Model::preventLazyLoading(! app()->isProduction());

"color: #6B7280;">// This will throw an exception in dev "color: #8B5CF6;">if lazy loading occurs
$users = User::all();
"color: #8B5CF6;">foreach ($users "color: #8B5CF6;">as $user) {
    echo $user->posts->count(); "color: #6B7280;">// Exception thrown
}

📅Filament 3 includes built-in support for complex table filters with date ranges

Code Example

"color: #6B7280;">// Advanced filters in Filament 3
DateRangeFilter::make('created_at')
    ->placeholder('Select date range')
    ->displayFormat('d/m/Y')
    ->closeOnDateSelection()
    ->separator(' - ');

Inertia.js v2 supports deferred props for lazy-loading expensive data after page render

Code Example

"color: #6B7280;">// Deferred props in "color: #8B5CF6;">Inertia v2
"color: #8B5CF6;">return "color: #8B5CF6;">Inertia::render('Dashboard', [
    'user' => $user,
    'stats' => "color: #8B5CF6;">Inertia::defer(fn () =>
        expensiveStatsCalculation()
    ),
]);

📈Pest 4 can generate beautiful HTML coverage reports with interactive charts

Code Example

"color: #6B7280;">// Coverage reports in Pest 4
./"color: #8B5CF6;">vendor/bin/pest --coverage --coverage-html=coverage-report

"color: #6B7280;">// Or with specific thresholds
./"color: #8B5CF6;">vendor/bin/pest --coverage --min=80

🏷️Laravel 11's new cache tags allow for more granular cache invalidation

Code Example

"color: #6B7280;">// "color: #8B5CF6;">Cache tags in Laravel 11
"color: #8B5CF6;">Cache::tags(['users', 'posts'])->put('user.1', $user, 3600);

"color: #6B7280;">// Invalidate all caches with 'users' tag
"color: #8B5CF6;">Cache::tags(['users'])->flush();

Join Laravel Meetup Stockholm

Want to learn more Laravel tips and tricks? Join our community meetup for hands-on learning and networking with fellow Laravel developers.

Learn About Our Next Meetup