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 Playwright-powered browser testing with device emulation

Code Example

"color: #6B7280;">// Pest 4 browser testing (Playwright-powered)
"color: #8B5CF6;">it('works on mobile', "color: #8B5CF6;">function () {
    visit('/', device: 'iPhone 14 Pro')
        ->assertSee('Welcome')
        ->assertNoJavascriptErrors();
});

"color: #6B7280;">// Visual regression testing
"color: #8B5CF6;">it('matches 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 4 tables are 2-3x faster with aggressive performance optimizations

Code Example

"color: #6B7280;">// Filament 4 table performance improvements
"color: #6B7280;">// Tables now render with far fewer Blade components
"color: #6B7280;">// Per-cell views replaced with optimized PHP logic

"color: #6B7280;">// Nested resources in v4
"color: #8B5CF6;">php artisan make:filament-resource Product --nested

"color: #6B7280;">// Non-model-backed data support
Table::make()
    ->data($customArrayData)
    ->paginated()
    ->searchable();

โšก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 supports test sharding for CI/CD parallel execution across machines

Code Example

"color: #6B7280;">// Test sharding for GitHub Actions
./"color: #8B5CF6;">vendor/bin/pest --shard=1/4  # Run shard 1 of 4

# In GitHub Actions workflow:
strategy:
  matrix:
    shard: [1, 2, 3, 4]
steps:
  - run: ./"color: #8B5CF6;">vendor/bin/pest --shard=${{ matrix.shard }}/4

๐Ÿงน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 4 introduces built-in Multi-Factor Authentication (MFA)

Code Example

"color: #6B7280;">// Filament 4 built-in MFA support
"color: #6B7280;">// Enhances security beyond standard email/password

"color: #6B7280;">// New Slider component for ranges/ratings
Slider::make('rating')
    ->min(1)
    ->max(5)
    ->step(0.5);

"color: #6B7280;">// Code editor component with syntax highlighting
CodeEditor::make('config')
    ->language('php');

๐Ÿ›ก๏ธ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 4 uses TipTap for rich text editing with custom plugin support

Code Example

"color: #6B7280;">// Filament 4 switched from Trix to TipTap
RichEditor::make('content')
    ->toolbarButtons([
        'bold', 'italic', 'link',
        'h2', 'h3', 'bulletList'
    ])
    ->extraAttributes(['class' => 'prose']);

"color: #6B7280;">// Create custom TipTap plugins for extended functionality

โณ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 offers unified code coverage combining backend and browser tests

Code Example

"color: #6B7280;">// Unified coverage in Pest 4 (backend + browser)
./"color: #8B5CF6;">vendor/bin/pest --coverage --coverage-html=report

"color: #6B7280;">// Smoke testing multiple pages at once
"color: #8B5CF6;">it('all pages work', "color: #8B5CF6;">function () {
    $pages = visit(['/', '/about', '/contact']);
    $pages->assertNoJavascriptErrors()
          ->assertNoConsoleLogs();
});

๐Ÿท๏ธLaravel 12 adds Str::plural with prependCount and failover queue driver

Code Example

"color: #6B7280;">// Laravel 12 Str::plural with prependCount
Str::plural('item', 5, prependCount: true);
"color: #6B7280;">// Returns: "5 items"

"color: #6B7280;">// Failover queue driver for automatic failover
"color: #6B7280;">// config/queue."color: #8B5CF6;">php
'connections' => [
    'failover' => [
        'driver' => 'failover',
        'connections' => ['redis', 'sqs', 'database'],
    ],
],

๐Ÿ“œLaravel 12 introduces InfiniteScroll component for React, Vue, and Svelte

Code Example

"color: #6B7280;">// InfiniteScroll component (Nov 2025)
"color: #6B7280;">// React/Vue/Svelte support out of the box

    {(post) => }


"color: #6B7280;">// Works seamlessly with "color: #8B5CF6;">Inertia::merge()

โฑ๏ธHttp::batch() now supports defer() for background execution after response

Code Example

"color: #6B7280;">// Deferred HTTP batch requests (Nov 2025)
"color: #6B7280;">// Execute batch after sending response to user
Http::batch([
    fn () => Http::get('api/analytics'),
    fn () => Http::get('api/notifications'),
    fn () => Http::post('api/webhooks'),
])->defer();

"color: #6B7280;">// User gets fast response, batch runs in background

โœจInertia v2.2 adds View Transitions API support for smooth page animations

Code Example

"color: #6B7280;">// View Transitions in "color: #8B5CF6;">Inertia v2.2 (Nov 2025)
"color: #6B7280;">// Smooth animations between page navigations
"/dashboard" viewTransition>
    Dashboard


"color: #6B7280;">// CSS for custom transitions
::view-transition-old(root) {
    animation: fade-out 0.3s ease-out;
}
::view-transition-"color: #8B5CF6;">new(root) {
    animation: fade-in 0.3s ease-in;
}

๐Ÿ˜Laravel 12 supports PostgreSQL 18 virtual generated columns

Code Example

"color: #6B7280;">// PostgreSQL 18 virtual columns (Nov 2025)
Schema::create('products', "color: #8B5CF6;">function (Blueprint $table) {
    $table->decimal('price');
    $table->decimal('tax_rate');

    "color: #6B7280;">// Virtual generated column
    $table->decimal('total_price')
          ->virtualAs('price * (1 + tax_rate)');
});

๐ŸงชLaravel Sail now supports Pest 4 browser testing out of the box

Code Example

"color: #6B7280;">// Run Pest 4 browser tests in Sail
./"color: #8B5CF6;">vendor/bin/sail pest --browser

"color: #6B7280;">// Docker configured for Playwright headless
"color: #6B7280;">// Works with device emulation and screenshots
./"color: #8B5CF6;">vendor/bin/sail pest tests/Browser

"color: #6B7280;">// Light/dark mode testing
visit('/', colorScheme: 'dark')
    ->assertSee('Dark Mode');

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