---
title: Laravel + Cloudflare D1 speedrun
url: "https://aaronfrancis.com/videos/laravel-cloudflare-d1-speedrun"
path: "/videos/laravel-cloudflare-d1-speedrun"
type: video
author: Aaron Francis
published: 2024-04-09
topic: "Laravel & PHP"
keywords: [cloudflare d1, laravel, sqlite, cloudflare workers, database migrations, cloudflare, edge database, time travel, query insights, l1 package, git deployment, serverless database]
youtube_url: "https://www.youtube.com/watch?v=htAOyy3-E9c"
site_index: "/llms.txt"
keyword_index: "/llms/keywords.txt"
---

# Laravel + Cloudflare D1 speedrun

## Chapters

- Intro to Website Setup
- Using SQLite and Git for Deployment
- Cloudflare for Static Site Speeds
- Deploying with Cloudflare API
- Cloudflare Reaches Out About D1 Database
- Introduction to Cloudflare D1
- Laravel Speedrun with D1
- Setting Up D1 with Laravel
- Running Migrations on D1
- Accessing Data from Cloudflare Workers
- Use Cases for Laravel and Cloudflare Workers
- Insights: Tracking Database Queries
- Time Travel with Cloudflare D1

## Transcript

**Aaron Francis:** Not that long ago, I made a video about my personal website, aaronfrancis.com. Great website, great video. Go watch the video. In that video, I talk about how I use SQLite as my database, and I commit it all to the Git repo and ship it off to Laravel Vapor. I thought this was really clever, so I told my friend and podcast co-host, Ian, about it, and he thought I was crazy.

**Aaron Francis:** So to get static site speeds, I have Cloudflare, which you love, active investor.

**Unidentified:** Love the Cloudflare. Oh man, it's up 5% today.

**Aaron Francis:** Love the Cloudflare.

**Unidentified:** Let's go!

**Aaron Francis:** Oh.

**Unidentified:** Let's go!

**Aaron Francis:** Check it every freaking day.

**Unidentified:** Cloudflare, baby.

**Aaron Francis:** So to get the static site speeds, I have this rule in Cloudflare that's just brute force cache-

**Unidentified:** I'm with you

**Aaron Francis:** ... everything-

**Unidentified:** I'm with you all the way on this

**Aaron Francis:** ... all around.

**Unidentified:** Cache everything.

**Aaron Francis:** And then, and then-

**Unidentified:** In-

**Aaron Francis:** And, and then-

**Unidentified:** Forever

**Aaron Francis:** ... okay, so we're on, we're on the straight and narrow so far.

**Unidentified:** That's where-

**Aaron Francis:** SQLite, boring as could be. Laravel-

**Unidentified:** Perfect alignment

**Aaron Francis:** ... Cloudflare, active investor.

**Unidentified:** I love it.

**Aaron Francis:** Okay, so not crazy yet.

**Unidentified:** Nope.

**Aaron Francis:** And so when I deploy, I make a API call to Cloudflare that says, "Blow everything up. I'm coming, baby."

**Unidentified:** Right.

**Aaron Francis:** And so it just, it just kills the cache.

**Unidentified:** Yep. I'm with you.

**Aaron Francis:** And then the next time somebody requests it, it'll hit Vapor, it'll run through Cloudflare, it'll cache.

**Unidentified:** Yep.

**Aaron Francis:** What is crazy about that?

**Unidentified:** So that's all not crazy. But I think-

**Aaron Francis:** That's all it is.

**Unidentified:** No, but you're leaving out a step. In the video, you had this whole other step where you do some local stuff, and then you push the local stuff to the server, but you don't need to do that stuff. It can-

**Aaron Francis:** What are you talking about? What are you talking about? Now, I'm never gonna tell Ian that he's right about anything, honestly, but especially not about this. One thing, one thing that is a little bit weird is committing that SQLite database to the Git repo. In that video, I talked a lot about Cloudflare and how I use their aggressive caching to make my site extremely fast, and they reached out and said, "Hey, we actually have a database that you can use.

**Aaron Francis:** Do you wanna try D1? It's generally available now. Do you wanna do a video on it?" And I said, "You bet I do." D1 is Cloudflare's serverless database offering. It's built on top of SQLite, and since it's serverless, you pay by usage instead of paying a fixed amount. I'll tell you more about that in a second, but before we do, I wanna do two things. The first is Laravel speed run.

**Aaron Francis:** How quickly can we get D1 working together with Laravel? And the second is what are some potentially interesting use cases once D1 is your database? Let's do the speed run first. You can see here that I have no D1 databases. You could create it right here by clicking Create Database. But we're gonna hop over to the terminal and say npx wrangler, and that's their little command line tool, d1 create, and we're just gonna call this, we'll call it blog-dev.

**Aaron Francis:** So we're gonna create a database. It should spit out a database ID, which you're welcome to try to use, but it's already been deleted. So I'm gonna copy this database ID and come put it in my Laravel environment, uh, file. There are a few other keys in here, like my, uh, API token and account ID. I am not gonna show you those because my account ID doesn't change.

**Aaron Francis:** So I'm just gonna put the database ID in here. And then to combine Laravel and D1, there's a package that sits in the middle called L1, which is a community package. Great name, D1 Laravel L1. Love it. I've already installed it 'cause that part's boring, so let's come over to the docs. L1 usage with raw PDO, interesting, not what I'm after.

**Aaron Francis:** Usage with Laravel, that is what I'm after. So I'm gonna copy out the D1 connection part, and we're gonna come over to database. And right here, we're gonna put D1. I don't need to change anything 'cause I already have these three environment variables set up. Um, it does go over, it does go over Cloudflare's API, which is why you need a custom driver for this.

**Aaron Francis:** So we're gonna come up here and change the default from SQLite to D1. Now, with any luck, we can hop over here, clear this out, php artisan migrate. We should be running these migrations against our D1 database. If we come back to the dashboard and refresh, you see we do have the blog-dev database, and we look, there are all the tables.

**Aaron Francis:** And if you wanted to poke around with the data, you could click into one. This is the Laravel data. I didn't populate my tables with any data, so that's the only table that has anything in it. Not bad for a speed run, right? That took, I don't know, maybe less than a minute, which is pretty good. I'm pretty happy about that. I'm just testing this from my local machine, so there is a little bit more latency from where I am to where the database is, and I think that's an interesting thing that we might need to consider is this database is typically supposed to be used

**Aaron Francis:** with Cloudflare workers or Cloudflare pages, but we're using it with a full-on Laravel application. And this is where I think it gets interesting from a Laravel application standpoint. Yes, we just set up the database to be our Laravel database. We have Eloquent. That all works fine and dandy. You can also access that data from Cloudflare workers, which means you can manipulate or do or query the data before it ever reaches your Laravel application.

**Aaron Francis:** So you could do redirects, you could do caching, you could do responses and requests, headers. You could do all kinds of stuff before it ever gets to your Laravel app with the same data that your Laravel app is relying on. That's what I wanna hear from you on. What can you possibly dream up of doing with the combination of Laravel and Cloudflare workers?

**Aaron Francis:** I'm gonna show you two more things before we go. One is the insights that come with this database, and one is time travel, which is like automated backup that you never have to turn on, and it's point-in-time recovery. So let me show you, let me show you the insights first. Their insights are great 'cause you can query all different types of things from your database, so we're just gonna say insights on the database that we just created, sort by time, show us 10.

**Aaron Francis:** So this is gonna show us the 10 slowest queries, and this is all available via API, so it returns this nice JSON response. So you can potentially imagine how you could build this into some sort of alerting, reporting, notification system so you can keep track of what your slowest queries are. They do have a little bit of insights in the actual, uh, browser here.

**Aaron Francis:** You can come over here and see the queries and the latency and the metrics, that sort of thing. Um, but I like, I like using the API 'cause you can get exactly what you're looking for out of it. Metrics are very cool, but nothing is cooler than time travel. So let's talk about time travel generally. It is possible. However, you can only move forward through time, which kind of defeats the whole point, right? With Cloudflare's time travel for your database, which is slightly different, you can just travel back in time to any point in time in the past 30 days and restore your database.

**Aaron Francis:** There's nothing to configure. There's nothing to enable. More importantly, there's nothing to forget to enable. So you can just pick any point in time, hit Restore, and you are good to go. Y'all, I am always going to love databases, maybe now more so than ever. All of these books back here, those are all database books. I just got a bunch of new ones. The SQLite revolution is upon us.

**Aaron Francis:** I am here for it. I am excited. What I wanna hear from you in the comments is how do we combine Laravel with Cloudflare workers using D1 in the middle? There's something interesting there, and I want you to tell me what it is. Cloudflare just wrapped up their developer week, so they just announced a ton of stuff, including, uh, D1 going GA, so I'll leave a link to that in the description.

**Aaron Francis:** Thank you, Cloudflare, for helping me make this video. Until the next time, see ya.

---

## Related on aaronfrancis.com

- [The Big Reveal](/podcast/the-big-reveal-675733cf) *(Podcast · 2025-01-28 · shared: sqlite, laravel, cloudflare)*
- [Making videos developers actually want to watch](/podcast/making-videos-developers-actually-want-to-watch-6e3ad549) *(Podcast · 2024-06-03 · shared: sqlite, laravel, cloudflare workers)*
- [Super Epic Crazy with Adam Wathan](/podcast/super-epic-crazy-with-adam-wathan-81c46343) *(Podcast · 2024-03-27 · shared: laravel, sqlite, cloudflare)*
- [Static site generators & personal websites](/podcast/static-site-generators-personal-websites-knj6zl) *(Podcast · 2023-12-14 · shared: laravel, sqlite, cloudflare)*
- [About](/about) *(Page · 2026-11-25 · shared: laravel, sqlite)*

## Relevant Resources from Aaron Francis

- **[Solo](https://soloterm.com)** (overview on site: [/software](/software)): All-in-one agentic development platform and terminal workspace built by Aaron Francis for orchestrating processes and AI coding agents.
- **[MySQL for Developers](https://databaseschool.com)** (overview on site: [/courses](/courses)): Full video course covering MySQL indexing, deferred joins, pagination, query plans, and schema design for application developers.

## Search aaronfrancis.com (2-Hop Static Keyword Index)

Pick the alphabetical shard matching any topic to find exact pages across all articles, newsletters, videos, talks, and podcast transcripts (every shard is < 40 KB):
[A-B](/llms/keywords/a-b.txt) · [C](/llms/keywords/c.txt) · [D-E](/llms/keywords/d-e.txt) · [F-G](/llms/keywords/f-g.txt) · [H-J](/llms/keywords/h-j.txt) · [K-L](/llms/keywords/k-l.txt) · [M-N](/llms/keywords/m-n.txt) · [O-P](/llms/keywords/o-p.txt) · [Q-R](/llms/keywords/q-r.txt) · [S](/llms/keywords/s.txt) · [T-Z](/llms/keywords/t-z.txt) · [Directory](/llms/keywords.txt) · [Site Map](/llms.txt)

Shards for this page's topics: `cloudflare d1` ([C](/llms/keywords/c.txt)), `laravel` ([K-L](/llms/keywords/k-l.txt)), `sqlite` ([S](/llms/keywords/s.txt)), `database migrations` ([D-E](/llms/keywords/d-e.txt)).

## About Aaron Francis (Current Context)

Aaron Francis is VP of Marketing and Community at [Laravel](https://laravel.com), founder of [Try Hard Studios](https://tryhardstudios.com), creator of [Solo](https://soloterm.com), co-host of [Mostly Technical](/podcast), and author of [Mastering Postgres](/courses), [High Performance SQLite](/courses), [MySQL for Developers](/courses), and [Screencasting.com](/courses). Full bio: [/about](/about) · Current focus: [/now](/now).
