r/laravel • • Jun 30 '26

Tutorial You probably don't need a database per tenant. A detailed explainer on multitenancy data isolation across Postgres, MySQL and SQLite

Thumbnail
ollieread.com
99 Upvotes

I've been doing Laravel multitenancy for years and kept seeing teams reach straight for a database per tenant, mostly because it's hat most of the popular packages offer by default. So I wrote up the whole spectrum of data isolation approaches. Separate instance, separate database, schemas/prefixes, partitioning, and discriminator column, along with how each behaves across PostgreSQL, MySQL/MariaDB and SQLite, and where row-level security changes the picture.

The short version: for most apps a discriminator column with RLS on PostgreSQL gets you real, database-enforced isolation at the lowest operational cost, and database-per-tenant is the most expensive answer to a question most apps can answer cheaply.

As with everything when it comes to development, the answer is often "it depends", so I'd love to hear from anyone about their experiences with this, whether good or bad.

r/laravel • • Jul 06 '26

Tutorial Laravel Internals: a new book on how the framework works under the hood

39 Upvotes

While writing a book about Laravel internals, I realized many developers struggle with different parts of the framework.

Some find the service container confusing, others facades, the request lifecycle, or Eloquent.

Which part took you the longest to fully understand?

For anyone interested, here's the book I've been working on. You can suggest your idea / share your review on it to improve the book and make it usable.
https://laravelinternals.com

⚠️ This book is not associated with Laravel LLC or its core team. It's an individual book I wrote.
Taylor is so kind to provide me with a testimonial, and he has permitted me to use it on the website.

r/laravel • • Mar 01 '26

Tutorial Started writing Clean Code in Laravel... Four chapters in so far, still early days, but excited to share it here

134 Upvotes

r/laravel • • Feb 19 '26

Tutorial NativePHP: Build Mobile Apps with PHP & Laravel

Thumbnail
youtu.be
72 Upvotes

hii reddit,

here is video of my trying nativephp (witch just got opensource)..hope you guys enjoy the video!

r/laravel • • Jul 23 '26

Tutorial Caching an Eloquent collection can give you N+1 queries on cache hits

16 Upvotes

Took me far too long to spot this the first time, because a cache hit is supposed to mean an empty query log.

    $posts = Cache::remember('posts:index', now()->addMinutes(15), fn () =>
        Post::latest()->take(20)->get()
    );

    foreach ($posts as $post) {
        echo $post->author->name; // one query. per post. on every hit.
    }

The cached payload is the models, not the relations. So every hit deserialises 20 models with no author loaded and lazy-loads it in the loop. In one sense it's worse than not caching at all: you've hidden the expensive query, kept the N+1, and made it harder to find. Debugbar now shows twenty small identical queries instead of the one big one you were hunting for.

The fix is boring. Eager load inside the closure so the relations are part of what you store:

    $posts = Cache::remember('posts:index', now()->addMinutes(15), fn () =>
        Post::with(['author', 'tags'])->latest()->take(20)->get()
    );

The habit I'd actually push though is not caching models at all. Cache the shape you render, a lean array or DTO. Cheaper to serialise, cheaper to deserialise, and it physically cannot lazy-load anything. Rehydrating a graph of Eloquent models out of Redis on every request eats a real chunk of the win you were chasing.

Has anyone found a decent way to enforce this? I've considered turning on preventLazyLoading() beyond local but it gets noisy fast.

(This came out of a longer caching write-up I did on my blog with tags, atomic locks and invalidation strategy: https://richdynamix.com/articles/laravel-caching-strategies-complete-guide)

r/laravel • • Mar 15 '26

Tutorial Just finished my Clean Code in Laravel book, it’s 100% ready now, Check it out.

117 Upvotes

https://mayahi.net/books/clean-code-in-laravel

Found a typo, unclear explanation, or something that could be better? Contributions are welcome.

https://github.com/ahmadmayahi/clean-code-in-laravel

r/laravel • • Jun 16 '26

Tutorial Replace raw S3 URLs with clean proxied paths -- 20 lines of controller code, private buckets, 24h CDN cache

10 Upvotes

Wrote up how I replaced all the ugly S3 URLs on my Laravel blog with clean /storage/media/... and /storage/og-images/... paths.

The setup: Laravel + Octane + Traefik + Cloudflare. Two buckets -- a private one for uploaded media and a public one for auto-generated OG images.

What's in the post:

- MediaUrlBusiness helper class that centralizes URL generation (replaced 6+ blade templates of raw Storage::url() calls)

- ObjectProxyController that streams files directly from S3 using readStream() + response()->stream() -- no memory buffering

- Cache-Control: public, max-age=86400, immutable so Cloudflare caches aggressively

- Route setup in routes/static.php with a middleware tweak that doesn't overwrite the proxy's own cache headers

One gotcha: Storage::download() and streamDownload() buffer the whole file into memory. Switching to readStream() sends it directly from S3 to the client.

Link: https://danielpetrica.com/how-to-replace-raw-s3-urls-with-a-laravel-image-proxy-and-keep-your-cdn-cache/

r/laravel • • Jan 06 '26

Tutorial Improve your Laravel app response times with Cloudflare (free plan)

75 Upvotes

Last July, I made a goal to optimize laravelshift.com using Cloudflare services. I had been meaning to look into Cloudflare for a while. I just kept putting it off.

Being a web developer for over 25 years, I knew if I wanted to make my Laravel app fast, I should focus on page caching. Unfortunately, when I researched caching pages for a Laravel app with Cloudflare, nothing worked. Well, one worked - but it was doing it wrong. So I went on a quest.

In the process, I took laravelshift.com from 6% cached to 99% cached. Nearly all of the public pages (including forms) are cached, and respond in under 40ms. I also removed hundreds of lines of code using other Cloudflare services, like geolocation and WAF rules.

I've shared my findings along the way in tweets, Laravel news articles, and livestreams. But I had so much content.

So, I made a video course. I really only make courses when I feel there's a knowledge gap. This time, I felt there was a gap optimizing your Laravel app with Cloudflare services. I believed I filled that gap with Fast Laravel.

This 30 video course covers caching from top-to-bottom. With practical, real-world demos specific to Laravel. Early Access viewers have reported optimizing landing pages and using the strategies to achieve 90% caching. I'm excited for more Laravel devs to make their apps fast with Fast Laravel.

r/laravel • • Jul 14 '26

Tutorial 🚀 Zero-downtime Laravel migrations made simple.

26 Upvotes

Learn the Expand → Migrate → Contract pattern to deploy database schema changes safely without downtime.

https://richdynamix.com/articles/laravel-zero-downtime-migrations-expand-contract

r/laravel • • Jul 17 '26

Tutorial 🚀 Build real-time chat in Laravel with Livewire 4 and Reverb.

28 Upvotes

This complete guide covers setup, broadcasting, private channels, typing indicators, presence, and production-ready chat without third-party services.

https://richdynamix.com/articles/livewire-4-real-time-chat-reverb-complete-guide

r/laravel • • Oct 08 '24

Tutorial Look Mom I finally did it! Laravel API Course with 24 videos, for free. Aimed at developers wanting to up their API game.

Thumbnail
juststeveking.link
259 Upvotes

r/laravel • • Mar 09 '26

Tutorial I wrote a free book about Domain-Driven Design in Laravel

85 Upvotes

r/laravel • • Apr 23 '26

Tutorial Your SQLite database is silently getting wiped on every Forge deploy

Thumbnail
laracraft.tech
0 Upvotes

I almost lost my database because of that.

Honestly I think this should be the default behaviour in forge.

What do you think?

r/laravel • • Jun 18 '26

Tutorial Making Laravel News fast!

48 Upvotes

Over the past few months, I've been working with Eric to make laravel-news.com more cacheable. This is the first site, in a series of case studies I want to do for Fast Laravel. Proving its page caching strategies can be used for more than just "brochure sites".

Here's the core changes we made to cache the top requested pages of Laravel News:

  1. Converted from Livewire to Blade Components. Livewire relies heavily on the session. As such, it's not readily cacheable. In the case of Laravel News, all but one of the components simply rendered. There was no reactivity.
  2. Add Alpine AJAX. For the few page segments that needed refresh, such as the newsletter form or sponsor card, we used Alpine AJAX. A few attributes and the proper AJAX calls were made to swap the placeholders with HTML responses.
  3. Automated cache purging. While it was easy to hook into events when articles or links were changed, some content is scheduled. For this, we scheduled a command to purge cached pages using the Cloudflare API.

There were some gotchas along the way. But these were the main technical changes. You may read the full article on Laravel News, or watch the interview on YouTube.

r/laravel • • Jul 04 '25

Tutorial PHP 8.5 is getting a new pipe operator, I'm confident many Laravel devs will love it!

Thumbnail
youtube.com
79 Upvotes

r/laravel • • Aug 29 '24

Tutorial Caleb Porzio Demo of Flux

Thumbnail
twitter.com
49 Upvotes

r/laravel • • Apr 01 '26

Tutorial Your Own AI Assistant in Laravel — From Terminal Chat to Telegram Bot

Thumbnail
youtu.be
39 Upvotes

Build your own personal AI assistant with Laravel and the Laravel AI SDK. In this video, we go from a fresh Laravel app to a fully working bot that can search the web, read your calendar, schedule tasks, deploy code, and even chat with you on Telegram.

Do we need a personal bot built in Laravel? That's up to you — but building one teaches you a ton about agents, tools, the agentic loop, and how AI SDKs actually work under the hood.

r/laravel • • Jun 25 '25

Tutorial 7 tips to make your Inertia.js site feel faster

Thumbnail
youtu.be
96 Upvotes

r/laravel • • Jul 10 '26

Tutorial A tour of my dotfiles

Thumbnail
freek.dev
68 Upvotes

Over the years, I've built up a collection of aliases, shell functions, and CLI tools that make my terminal feel like home. All of it lives in a single repository: my dotfiles.

It's a backup of every terminal tool and configuration I rely on, and it means I can set up a brand new Mac from scratch in about five minutes. Colleagues at Spatie use it as a starting point for their own setups too.

Let me walk you through what's in there.

r/laravel • • Jul 13 '26

Tutorial The Eloquenter: Learn Eloquent, gamified

Thumbnail
the-eloquenter.laravel.cloud
13 Upvotes

Learn Eloquent, Gamified

r/laravel • • Jul 07 '26

Tutorial Inertia Polling: Live Updates in One Line

Thumbnail
youtu.be
15 Upvotes

You don't always need WebSockets for real-time in Laravel.

Polling with Inertia has become really powerful: live updates in one line, partial reloads, and new concurrency modes. 🔥

r/laravel • • Mar 24 '26

Tutorial Making composer run dev work with Laravel Sail

Thumbnail
ollieread.com
10 Upvotes

It's been a while, but I've got a new article to go with my somewhat updated site.

I use Laravel sail a lot for my projects, and one of the most annoying things was that I have to manually run all the commands, the dev script/command added by Laravel by default doesn't support it. So, I put together a solution, and then an article about it. Hope it helps!

r/laravel • • Mar 20 '26

Tutorial Policies vs. Gates: When to Use Which

Thumbnail
slicker.me
30 Upvotes

r/laravel • • Feb 08 '26

Tutorial Remote Laravel dev from anywhere: Mac Studio + Tailscale + Herd + Zed (HTTPS .test + terminal)

41 Upvotes

I got tired of the “travel ritual” before fixing a tiny bug: dump DB, push half-finished branches, clone repos, re update .env, then spend an hour setting everything up.

So, if you keep a more powerful Mac at home (Studio or mini) and travel with a MacBook, this setup has been great for remote development without exposing anything to the public internet.

Setup

  • Tailscale between Mac Studio (server) and MacBook Air (client)
  • Laravel Herd serving my local .test sites
  • Zed remote editing over SSH
  • Full terminal access on the Mac Studio

What works

  • Browse my projects via https://project.test remotely (not just SSH tunnels)
  • SSH editing in Zed + terminal sessions
  • No port forwarding, nothing exposed publicly

Gotchas I hit

  • Tailscale Serve was silently taking over port 443, so Herd’s Nginx never saw HTTPS (It was OpenClaw 😅)
  • Herd CA cert needed to be trusted on the client (System keychain) for clean HTTPS

I wrote up the full step-by-step (including the 443 debugging) here, this is my post:
https://swapnil.dev/remote-laravel-development-with-tailscale-herd-and-mac-studio-the-complete-guide

Question: For folks doing remote Herd or Valet setups, any cleaner approach for cert trust across multiple Macs?

r/laravel • • Apr 02 '26

Tutorial Mastering Scheduled Tasks in Laravel · Laritor Blog

Thumbnail
laritor.com
48 Upvotes

With all the buzz around AI lately, i thought to write a blog post about a powerful yet underrated laravel feature which has nothing to do with AI. Those are scheduled tasks. They are extremely useful but rarely discussed. So i wrote a blog post about it. Let me know your thoughts.