Laravel 12 Complete Guide: From Basics to Advanced

Published: Jul 03, 2025 4 min read
laravel 12 laravel 12 tutorial laravel 12 new features laravel reverb laravel pest testing laravel routing laravel 2025 php laravel guide laravel beginner to advanced laravel full guide

Laravel 12 is here — and it's smoother, smarter, and more developer-friendly than ever. Whether you’re a beginner exploring Laravel or a seasoned developer ready to dive into the latest features, this guide will walk you through Laravel 12 from the ground up.

📌 What is Laravel?

Laravel is a PHP framework designed to make web development easier and faster through elegant syntax, built-in tools, and a strong ecosystem. It's ideal for building everything from simple websites to enterprise-grade applications.


🛠️ What's New in Laravel 12?

Laravel 12 builds on its solid foundation with a few impactful upgrades:

  • Native Type Declarations: Laravel now encourages native type declarations (int, string, etc.) across controllers, models, and routes.

  • Slimmer Application Skeleton: The default Laravel 12 install is cleaner — fewer preloaded files, more room to scale.

  • Middleware Groups Overhaul: Middleware groups are now more flexible and better suited for modern API-first applications.

  • Enhanced Route Handling: Route caching is lightning-fast, with better support for closures and dynamic route generation.

  • Laravel Reverb (Real-time): Laravel now supports WebSockets natively using Laravel Reverb.

  • Pest Testing by Default: Pest comes pre-installed — beautiful, expressive testing is the new default.


🧱 Laravel 12 Basic Structure (Fresh Project)

Let’s take a quick look at a new Laravel 12 project:

bash
composer create-project laravel/laravel my-app cd my-app php artisan serve

Directory structure highlights:

  • app/Http/Controllers: All controller logic

  • routes/web.php: Your web routes

  • resources/views: Blade templates

  • app/Models: Your Eloquent models


📁 Routing in Laravel 12

php
use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); }); Route::get('/blog/{slug}', [BlogController::class, 'show']);

Now supports full route attributes:

php
Route::get('/admin', AdminController::class) ->middleware(['auth', 'verified']) ->name('admin.dashboard');

🧠 Powerful Blade Upgrades

Blade now supports attributes spreading, components, and slot-based templating more cleanly.

blade
<x-alert type="error"> <x-slot name="title">Error</x-slot> Something went wrong. </x-alert>

🧬 Eloquent ORM – Cleaner Than Ever

php
$posts = Post::where('status', 'published')->latest()->paginate(10); Post::create([ 'title' => 'New Blog Post', 'slug' => 'new-blog-post', 'content' => 'Here’s your content...', ]);

Also, native casts like AsEnumCollection, AsEncryptedArrayObject, and new Attribute::macro() make data handling intuitive.


📡 Laravel Reverb: Real-Time Built-in

Say goodbye to third-party socket servers. Laravel Reverb integrates WebSockets with native Laravel broadcasting.

bash
npm install laravel-reverb php artisan reverb:start

Then broadcast events from your backend directly:

php
broadcast(new NewMessage($message));

Frontend can listen using Laravel Echo or custom listeners.


🧪 Pest: Testing Made Elegant

Laravel 12 ships with Pest, a modern PHP testing framework:

php
test('homepage loads', function () { $this->get('/')->assertStatus(200); });

Write expressive tests without boilerplate. It’s perfect for both TDD lovers and beginners.


🔐 Laravel Breeze / Jetstream Authentication

Want authentication quickly?

bash
composer require laravel/breeze --dev php artisan breeze:install blade npm install && npm run dev php artisan migrate

Or go advanced with Jetstream (teams, API tokens, etc.):

bash
composer require laravel/jetstream php artisan jetstream:install livewire

📈 Performance Upgrades

  • Faster route caching with php artisan route:cache

  • Eager loading on steroids: $query->with(['user', 'comments.author'])

  • Queues run smoother with Octane and Swoole integration


💡 Tips for Laravel 12 Developers

  1. Always use .env for config — Laravel 12 strictly separates environment settings.

  2. Stick to service containers for better dependency injection.

  3. Use model factories and seeders to quickly test logic.

  4. Upgrade Composer to v2+ to avoid compatibility issues.

  5. Keep PHP version ≥ 8.2 for Laravel 12 support.


🎯 Final Thoughts

Laravel 12 continues the framework’s tradition of being developer-first — with clean syntax, smart tools, and performance in mind. Whether you’re building a portfolio site, a blog, or a scalable SaaS, Laravel 12 has your back.


📥 Useful Links

Author
Paramjeet Yogi

Web Developer & Blogger passionate about Laravel and modern web development.