Laravel Bytes

Welcome to the home for Laravel-oriented content on Fly.io.

By Chris Fidao

Never Miss a Webhook

If your app ingests data from users (webhooks or similar), then it’s important not to miss any of that data. This is actually a bit scary. We need, like, a lot of uptime! The typical way to increase uptime smells like “scaling” and often feels like

Read more
By Kathryn Anne Tan

Custom Laravel Pulse Cards

Pulse delivers a dashboard of application metric cards. Beyond these are reusable templates and a record-and-aggregation system to help us craft custom cards tailored to our very needs. A Custom Requirement: Requests Per Machine In a previous article

Read more
By Kathryn Anne Tan

Monitoring Fly Machine Resource Usage with Laravel Pulse

Deploying an app to production may at the first few hours leave a sense of blindness on the state of our application. Questions like—Is every request going through smoothly? Will the servers suddenly run out of resource during some data crunching pro

Read more
By Johannes Werbrouck

Reusable Input Components without Livewire, with Livewire

If you prefer watching a video instead of reading an blog post: Dan Harrin has a video up on Laracasts that touches on the exact same topics as this article. Dan Harrin is of course the creator of Filament, so you will be in very good hands! Check out

Read more
By Chris Fidao

Autoscaled Queue Workers

Fly Machines let you programmatically create and manage fast micro VMs. They’re great for scaling! One thing you might want to scale is queue workers. I made a thing™ that can do this, automatically. The Goal I wanted to do the least amount of work,

Read more
By Kathryn Anne Tan

Streaming updates with Livewire and Fly Machines

Previously, we looked into displaying progress in bulk processing of data. Just with one request, we were able to stream updates to the UI as each data completed processing thanks to the wire:stream directive. This allowed the UI to get updated real

Read more
By Chris Fidao

Making the CLI and Browser Talk

The CLI and web browser don’t really talk to each other. Let’s force some communication and make it 🎃 wyrd 🎃. We’re going to let users create an account (“register”) in our app, using the CLI and their web browser. CLI as User Interface The flyctl (

Read more
By Kathryn Anne Tan

Checkboxes, and Streamed updates with Livewire

Imagine having a table with ten rows. Imagine even more, having a “Bulk Action” button above this table. When the user selects all ten rows from the table and clicks on the button, all ten rows are sent to the server for bulk processing. Each row is

Read more
By Kathryn Anne Tan

Livewire v3: Modelable, Events, and Data Sharing

Oftentimes, we use drop-downs in combination with other html elements to make our website interactive. One kind of interaction is inter-dependency amongst several drop-downs. This happens when changing a selected option of one drop-down affects the

Read more
By Kathryn Anne Tan

Re-usable, Dependent Dropdowns in Livewire v3

How do we create dependency among dropdowns that use the same, re-usable component? One way we can solve this is by utilizing Livewire’s powerful component nesting capabilities. Let’s check it out, here’s a repository for reference. Problem We have

Read more
Fly Machines with Laravel
Part 3

Ad Hoc Tasks, GitHub Actions Style

We’re going to create a setup where we can instruct Fly.io to spin up a VM and run some code. The code will read an instructions.yaml file and follow its instructions. The neat part: We can create the YAML file on-the-fly when we spin up the VM. Th

Read more
By Kathryn Anne Tan

SPA NavBars and Highlighting, Livewire v3 Style!

Livewire’s new wire:navigate directive is brilliant. It delivers the combined forces of SEO-friendly rendering, and the smoothness of an SPA powered user experience. Today, we’ll create an SPA powered NavBar to provide seamless page navigation acros

Read more
By Chris Fidao

A NativePHP Example

NativePHP is out (in alpha currently), and I’ve had a great time building a desktop app in Laravel. Along the way I’ve discovered a few not-yet-documented goodies that I’m excited to share. Writing Laravel and seeing it translated into “native” des

Read more
FilamentPHP
Part 3

FilamentPHP: Shooting lasers at the moon

Did you know that there are reflectors on the moon? The Apollo missions left them on the surface of the moon for scientists on earth to shoot lasers at. By measuring the time it takes for the laser to go to the moon and back, the scientists can calcu

Read more
By Chris Fidao

Livewire 3 Forms

Forms are why I use Laravel. Anything that abstracts away the tedium of form security, validation, user-messaging (“hey this is required”), and saving state is my favorite thing. This is, in fact, a huge part of what keeps me using Laravel over any o

Read more
By Chris Fidao

Chat Widget with Livewire 3's Persist

We’re going to create a new app, add Livewire 3, and show how to persist a chat widget while navigating through the app. Here’s a GitHub repository with the final code. Wrap text Copy to clipboard

Read more
By Chris Fidao

Checking out toRawSql

In the recent past, we were able to dump out the SQL our query builder was generating like so: Wrap text Copy to clipboard $filter = 'wew, dogs'; // Using the `toSql()` helper DB::table('

Read more
By Chris Fidao

Checking Out Sub-Minute Scheduling

One of Laravel’s new, fun enhancements is the ability to run scheduled commands (or jobs) more than once per minute! Notoriously, CRON can only run tasks every 1 minute or slower. Laravel’s scheduler, typically driven by CRON, therefore only ran onc

Read more
FilamentPHP
Part 2

FilamentPHP: Adding some style

Let’s be real here: FilamentPHP has great styling out of the box, using tailwindcss and a coherent set of components. While beauty may be subjective, it’s a clear and inoffensive style anyone can appreciate. But let me ask you this: How do you reac

Read more
By Chris Fidao

Extending Laravel with Managers

Most Laravel libraries that have drivers use a Manager class. A “driver” is an implementation of some library, but (generally) using a different underlying technology. A few example Laravel libraries with drivers (multiple implementations) are: Que

Read more
By Kathryn Anne Tan

Debugging Tests: A look into assertCommandCalled

Have you ever written a test case, expecting it will pass, only to find out it doesn’t? Today, we’ll create a test for a Laravel Zero console command, and use its assertCommandCalled helper to assert one command calls another. We’ll then see how ea

Read more
By Chris Fidao

Handling Signals in Laravel

Laravel queues are stopped gracefully. What does this mean? During a deployment, you likely restart your queue workers using something like artisan queue:restart or supervisorctl restart <worker-name>. Laravel has graciously noticed that we don’t

Read more
FilamentPHP
Part 1

FilamentPHP: a first look

As Laravel developers we know how productive a framework can be: It provides a set of common components, reusable functionality and most importantly, a set of guidelines that make everyone using the framework more efficient. Knowing this, the fine f

Read more
By Chris Fidao

Running Laravel Workers

We’re going to talk about running Laravel as a worker on Fly.io. This isn’t really anything special (we aren’t out to make things hard), but it’s useful to see how it essentially becomes a lesson in Docker. The “usual” use case on Fly.io is running

Read more
By Kathryn Anne Tan

Laravel, React, and Inertia SSR on Fly.io

Need to run a Laravel backend along with a React frontend? That’s going to be a piece of cake with Inertia! Inertia allows us to work in both monolithic Laravel land, and our preferred (Inertia-supported) frontend framework or library. What’s more,

Read more
By Chris Fidao

Laravel Queues with Other Languages

Learning multiple programming languages is good — there are a lot of benefits! One such benefit is the ability to use what a language is strongest at. Some top-of-mind examples include Python’s various data-munging libraries, or Go’s concurrency to

Read more
By Kathryn Anne Tan

Improving Client Side Pagination with Livewire

The bane of client side pagination stems from our retrieval of entire bulky data sets in one go. But, do we really need to get the entire data set all at once? In this article, we’ll apply a combination of data allowance and accumulation strategies

Read more
By Chris Fidao

Full Stack Laravel

You can use fly launch to get you up and running quickly with Laravel, but let’s talk about all the other stuff you probably want: Redis MySQL cron (Laravel Scheduler) Queues We’re gonna spin up a new Laravel installation, add some user authentic

Read more
By Chris Fidao

Parsing Recipes with Robot Help

This is NOT a story about how Javascript stole 2 hours of my life, and PHP rescued me - in 6 minutes. That did happen, but I digress. The real story is: Recipe sites are bloated. Rumor has it that this is because you can’t copyright a recipe, but ca

Read more
By Johannes Werbrouck

Console Applications with Laravel Zero

Here’s a news flash: You can write console applications with Laravel! Actually, it’s kinda with Laravel and kinda without. Let’s take a closer look at Laravel Zero and some cool things you might want to know about! Support for Facades First off: ther

Read more
By Kathryn Anne Tan

Creating a Middleware to Globally Log Submissions in Livewire

Ever implemented logic that applied to multiple Livewire components? Why not use a middleware to make it available across Livewire components? For example: Imagine having two Livewire components that handle two different form submissions. If, say, e

Read more
By Kathryn Anne Tan

Securing Access to Livewire components with Inline Policies, Traits, and Middlewares

How do we safeguard Livewire components against unauthorized access? How do we restrict access to its view or specific action based on a current user’s permissions? Laravel Policies In this article we’ll go through three different ways to restrict ac

Read more
By Chris Fidao

Prometheus Metrics in Laravel

It’s almost a hidden feature - Fly.io provides Grafana dashboards with helpful metrics for all of your Fly.io apps. All you have to do is head to https://fly-metrics.net/. 👉 Here’s the kicker: If your app publishes some metrics, Fly.io will read

Read more
By Johannes Werbrouck

Invoice PDF generation with Browsershot

Invoicing is a hugely important part of any business. By having your Laravel app generate invoices automatically, you can make the life of your users a lot easier and we all know that means they’ll hang around longer and be more keen to use your apps

Read more
By Kathryn Anne Tan

Sharing Google Maps Data across Separate Livewire Components

Let’s say we have separate Livewire components for: A Google Map Element - an interactive map for adding and deleting location markers A Search box Element - to re-focus the Google Map element to a user given location A Drop Down Element - to filt

Read more
By Johannes Werbrouck

Cost-Effective Queue Workers With Fly.io Machines

Fly.io machines have been announced and have been made the default way new apps will be run on Fly.io’s platform. They have many advantages, and one of them is their super-fast boot times. In this article, I’ll show you how to use machines to run bo

Read more
By Chris Fidao

Tricks for Running Commands with Laravel Process

Laravel 10 has released the Laravel’s Process facade, which make running external commands super easily. Wrap text Copy to clipboard $result = Process::run("php -v"); echo $result->output(

Read more
By Kathryn Anne Tan

No-Upload, Batched Import of Data with SheetJS CE and Livewire

When we think about first steps in importing spreadsheet data, we usually think of uploading the file first to the server, before processing the import. But. What if we didn’t need to upload the file at all? In this article, we’ll import data from

Read more
By Chris Fidao

Figuring out SPAs

SPAs always are a bit fragile. Nevermind the game of “where’s the business logic?” (a rant I won’t bother writing), splitting the frontend from the backend makes hosting SPAs harder. The complications are mostly related to security concerns, such a

Read more
By Kathryn Anne Tan

Collecting Time Video Metrics with Livewire

Alright drumrolls. Because today, we’ll intercept three user-video interaction events, and use Livewire to easily send event data to our server! The Problem There are cases when we’d want to get insight on how users interact with the video files we d

Read more
By Chris Fidao

Autocomplete with Livewire

The deal with React is that I don’t want it, but I’m jealous of the quality of React components. Auto complete fields are an example. There’s a lot of hidden complexity and (even still) browser compatibility issues. Here’s the rub: There are so ma

Read more
By Johannes Werbrouck

Cart is now in session

Shopping carts don’t empty out when the user leaves the page. Why? Well, for that I’ll need to take you back in time. Cue the wavy flashback transition! Once upon a time, there was an everyday, regular, normal guy named Jack. Jack loved shopping onl

Read more
By Kathryn Anne Tan

Concurrent, Chunked, Multi-File Uploads with Livewire

Livewire offers a quick way to upload multiple files in one go with the use of its WithFileUploads trait. This however only uploads the files in one way: all files in one request, each file sent as a whole. There are times when we’d want to send th

Read more
By Kathryn Anne Tan

Progress Indicator with Livewire

In the article Chunked File Upload with Livewire we easily uploaded a file in separate, smaller chunks using Livewire’s upload function. Today, we’ll create a progress bar indicator to let our users know how much progress has been made uploading the

Read more
By Chris Fidao

Highly Available Postgres with Laravel

PHP and MySQL go together like peas and carrots. This is because they both let you get away with a lot of crap, like pretending numbers and strings are interchangeable. However, some people (within the PHP world) are rebels against the mainstream.

Read more
By Kathryn Anne Tan

Chunked File Upload with Livewire

Servers are configured to limit the size of requests they can accept. This is done to avoid long processing times, resulting unavailability, and potential security risks that come with processing large requests in one go. What happens when a user r

Read more
By Chris Fidao

Keeping Global Deployments in Sync

We’re a fan of NATS here at Fly.io. NATS enables your server instances to communicate with each other with very little hassle - think PubSub, although there are a few different ways to push data around with NATS. The general setup is to run 1 or mor

Read more
Fly Machines with Laravel
Part 2

Concurrent Tasks on Machines

Previously I wrote about spinning up Fly Machines to run tasks “on-demand”. Machines are great because they stop when a task finishes - no need to waste (paid) CPU cycles. However, I hand-waved over the need for concurrency. To run multiple tasks at

Read more
By Kathryn Anne Tan

Delayed Display of Isolated PDFs with Fly-replay and Livewire

Running our Laravel application close to our users reduces geographical latency. What’s more, with Fly.io, we get to easily do global deployments with just a few commands! However, as we’ve established in Taking Laravel Global, files stored in one

Read more
By Johannes Werbrouck

Invite-only Registration

How many of you remember the launch of Oneplus’ first product? It was called the Oneplus One and it was marketed as the flagship killer. The name was warranted: It had flagship specs for a lower price than the flagships that time. I remember buying o

Read more
By Johannes Werbrouck

User Levels, Enums and Policies, oh my!

Users are not equal. You heard me. Some users are above others. They are allowed to do more than other users. They can see things other users cannot see. Sometimes they can even remove lower-class users! Now, this is not a weirdly abstract horror m

Read more
By Kathryn Anne Tan

Bridging PHP and JavaScript with Livewire

What makes Livewire a gem is how it easily allows us to communicate data, methods, and events across PHP and JavaScript. No long code, no extra syntax—just straightforward, easy PHP-JavaScript communication. Version Notice. This article foc

Read more
Fly Machines with Laravel
Part 1

On-Demand Compute

We’re going to learn how to use Fly Machines to run short-lived tasks efficiently. This boils down to having a process to run (an artisan command, in our case), and a VM ready to run that command. The VM will start, run the command, and stop when th

Read more
By Kathryn Anne Tan

Offloading Data Baggage with Livewire

In Hoarding Order with Livewire we implemented a client paginated table that relies on data accumulation. Instead of waiting for an entire dataset to load, the table periodically received and accumulated smaller portions of the dataset using Livewire

Read more
By Chris Fidao

Streaming to the Browser with Livewire

We’re going to see how to stream content to the browser using Livewire. 🤔 What’s that mean? Here’s an example from Chipper CI, which runs “builds” when you push code to git. When a command is run (perhaps composer install), the build output is stre

Read more
By Chris Fidao

Global Notifications with Livewire

I’ve never met an app that didn’t make me wish for a global notification system. What’s that mean exactly? I always want an easy way to display notifications on any page of my application. It’s “global” because I can show it anywhere. Livewire (and

Read more
By Kathryn Anne Tan

Hoarding Order With Livewire

In this post we’ll craft ourselves a hassle-free ordering of groupable data across table pages, and land our users a lag-free pagination experience. In order to do so, we’ll use Livewire’s polling feature to accumulate ordered data, and keep a clien

Read more
By Johannes Werbrouck

Integrating the Elastic Stack (ELK) into a Laravel app on Fly.io

The Elastic stack is hugely powerful, and a great tool in any developer’s arsenal. Since this is an intro I’ll keep it simple but please let me know if you’re interested in seeing more of this! You can find me on twitter or in the Laravel category of

Read more
By Chris Fidao

Deus Ex Machina

I’ve been on the search for a remote development setup for the better part of 11 years. Originally this was due to falling in love with an underpowered Macbook Air. Now I’m older and impatient - I’m opting out of dependency hell. Recently, I landed

Read more
By Apród Illés

Reusable, Dynamic Tables with Laravel Livewire

Tables have always played an essential role in the history of web development. Decades ago, tables lived their golden age; they were used not only to structure data but also for the layout of web pages. It was easy to arrange things with tables, a <tr

Read more
By Chris Fidao

Taking Laravel Global

Fly.io puts your application close to your users by making global deployments easy. It’s literally just a few commands. Here’s an example of showing an app, currently in DFW (Dallas), scaled out to also include Frankfurt and Singapore:

Read more
By Chris Fidao

Multi-Region Laravel with PlanetScale

We’re going to see how to serve Laravel globally. Fly.io is great at serving your application from servers in multiple regions. PlanetScale is great at putting your data close to your application servers! We’re going to use PlanetScale Portals to r

Read more
By Chris Fidao

Deploying with Private Composer Packages

If you’ve read anything on Fly.io, you’ve probably noticed a snippet like this: We transmogrify Docker containers into lightweight micro-VMs and run them on our own hardware in racks around the world, so your apps can run close to your users. Fly

Read more
By Apród Illés

Customize a Laravel select component

When it comes to form elements, we might immediately reach for an open-source or paid library. Pre-built components speed up development and using well-tested, robust libraries take a lot of pressure off our shoulders. But what about when we need so

Read more