Laravel 11 Tutorial: What’s New and How to Upgrade

Laravel continues to evolve, and version 11 brings exciting improvements that make development more efficient and enjoyable. Whether you’re considering upgrading an existing project or starting fresh, understanding what’s changed is crucial for making informed decisions.

Before we dive into the specifics, let me ask: What’s your current experience with Laravel? Are you working with an existing Laravel application that you’re considering upgrading, or are you exploring Laravel 11 for a new project? Understanding your starting point will help us focus on the most relevant aspects.

What Makes Laravel 11 Special?

Laravel 11 introduces several game-changing features, but rather than listing them all at once, let’s explore what problems you might be trying to solve. Are you dealing with any of these common challenges in your current Laravel projects?

  • Performance bottlenecks in large applications
  • Complex configuration management
  • Tedious boilerplate code
  • Deployment and maintenance overhead
  • Database query optimization

Your answers will help us prioritize which Laravel 11 features will benefit you most.

Key New Features in Laravel 11

1. Streamlined Application Structure

Laravel 11 introduces a more minimal application structure. Take a moment to think about this: what files do you find yourself rarely modifying in a typical Laravel project?

The new structure removes several files that many developers never customize:

// Files removed in Laravel 11:
- app/Http/Kernel.php
- config/cors.php
- database/migrations/2014_10_12_000000_create_users_table.php
- database/migrations/2014_10_12_100000_create_password_resets_table.php
- database/migrations/2019_08_19_000000_create_failed_jobs_table.php

Question for reflection: How often do you actually modify these files in your projects? Laravel 11’s approach assumes most developers use defaults, moving customization to service providers when needed.

2. New Artisan Commands

Laravel 11 introduces several new Artisan commands that streamline development:

# Create a class-based model factory
php artisan make:factory PostFactory --model=Post

# Generate API resources with relationships
php artisan make:resource PostResource --collection

# Create form requests with validation rules
php artisan make:request StorePostRequest

Try this exercise: If you’re working on a current project, identify three repetitive tasks you do when setting up new features. How might these new commands address those workflows?

3. Enhanced Database Features

Per-Database Configuration

// config/database.php
'connections' => [
    'mysql' => [
        'driver' => 'mysql',
        'options' => [
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ],
        'dump' => [
            'dump_binary_path' => env('DB_DUMP_PATH', '/usr/bin'),
            'use_single_transaction',
            'timeout' => 60 * 5, // 5 minutes
        ],
    ],
],

Reflection question: In your database setup, have you ever needed different configurations for different environments? How would per-database configuration simplify your workflow?

Upgrade Path: Step-by-Step Guide

Before we proceed with the upgrade steps, let’s assess your current situation:

  1. What Laravel version are you currently running?
  2. How complex is your existing application?
  3. Do you have comprehensive tests in place?

Prerequisites Check

# Check your current Laravel version
php artisan --version

# Verify PHP version (Laravel 11 requires PHP 8.1+)
php --version

# Review your composer.json dependencies
composer show --outdated

Step 1: Backup and Preparation

# Create a backup of your database
mysqldump -u username -p database_name > backup_$(date +%Y%m%d).sql

# Create a new branch for the upgrade
git checkout -b laravel-11-upgrade

# Update your .env.example if needed
cp .env .env.backup

Checkpoint question: Have you identified any custom packages or modifications that might be affected by the upgrade? What’s your rollback plan if issues arise?

Step 2: Update Composer Dependencies

// composer.json
{
    "require": {
        "php": "^8.1",
        "laravel/framework": "^11.0",
        "laravel/tinker": "^2.8"
    },
    "require-dev": {
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.18",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^7.0",
        "phpunit/phpunit": "^10.1",
        "spatie/laravel-ignition": "^2.0"
    }
}
# Update dependencies
composer update

# Clear all caches
php artisan config:clear
php artisan cache:clear
php artisan view:clear

Step 3: Configuration Updates

Laravel 11 consolidates configuration. Here’s a thinking exercise: Review your current config files and identify which ones contain only default values.

// bootstrap/app.php (New in Laravel 11)
<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        channels: __DIR__.'/../routes/channels.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        // Customize middleware here
    })
    ->withExceptions(function (Exceptions $exceptions) {
        // Customize exception handling here
    })->create();

Step 4: Testing Your Upgrade

// Create a comprehensive test
<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class Laravel11UpgradeTest extends TestCase
{
    use RefreshDatabase;

    /** @test */
    public function it_maintains_core_functionality()
    {
        // Test your critical application paths
        $response = $this->get('/');
        $response->assertStatus(200);
        
        // Test database connectivity
        $this->assertDatabaseHas('users', [
            'email' => 'test@example.com'
        ]);
    }
}

Performance Improvements in Laravel 11

Let’s explore this together: What are the biggest performance bottlenecks you’ve encountered in your Laravel applications?

Common areas where Laravel 11 shows improvements:

  1. Faster Route Compilation # Before upgrade php artisan route:cache # Time: ~500ms for 100 routes # After Laravel 11 php artisan route:cache # Time: ~200ms for 100 routes (60% improvement)
  2. Optimized Query Builder // Laravel 11 automatically optimizes these patterns User::where('active', true) ->with(['posts' => function($query) { $query->latest()->limit(5); }]) ->get();

Best Practices for Laravel 11

1. Embrace the New Structure

Reflection point: How can you reorganize your existing code to take advantage of Laravel 11’s streamlined approach?

// Instead of multiple configuration files
// Use the new bootstrap/app.php approach
return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/health-check',
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->trustProxies(at: [
            '192.168.1.1',
            '10.0.0.0/8',
        ]);
    });

2. Leverage New Artisan Features

# Generate complete CRUD scaffold
php artisan make:model Post -mfsc
# Creates: Model, Migration, Factory, Seeder, Controller

# Create API resources with relationships
php artisan make:resource PostResource --collection

Troubleshooting Common Issues

Let’s anticipate problems before they occur. Based on your current setup, which of these scenarios might apply to you?

Issue 1: Custom Middleware Registration

// Old way (Laravel 10)
// app/Http/Kernel.php
protected $middleware = [
    \App\Http\Middleware\CustomMiddleware::class,
];

// New way (Laravel 11)
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->append(\App\Http\Middleware\CustomMiddleware::class);
})

Issue 2: Configuration File Conflicts

# If you have custom configurations that conflict
php artisan config:publish cors
php artisan config:publish sanctum

Next Steps and Learning Path

Now that we’ve covered the basics, what aspects of Laravel 11 are you most excited to implement?

Consider these learning priorities:

  1. If you’re upgrading an existing app: Focus on configuration migration and testing
  2. If you’re starting fresh: Explore the new application structure and Artisan commands
  3. If you’re performance-focused: Dive into the query optimizations and caching improvements

Recommended Learning Sequence

  1. Set up a test project with Laravel 11
  2. Migrate one small feature from your existing app
  3. Implement comprehensive testing
  4. Gradually migrate larger features
  5. Optimize performance using new features

Conclusion

Laravel 11 represents a significant step forward in framework evolution, emphasizing simplicity without sacrificing power. The key question for your next steps: Will you start with a fresh Laravel 11 project to explore these features, or begin planning an upgrade strategy for your existing application?

Remember, successful upgrades happen gradually. Start with understanding the changes, then implement them systematically while maintaining thorough test coverage.

What’s your next move? Are you ready to create a test Laravel 11 project, or do you need to address specific concerns about your current application first?


Have questions about implementing any of these Laravel 11 features? The Laravel community is incredibly supportive, and the official documentation provides detailed examples for each new feature.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top