Posts About Laravel
Laravel is a powerful PHP framework that simplifies web development with its elegant syntax and comprehensive toolkit. It streamlines tasks like routing, authentication, and caching, making it ideal for both simple and complex applications.
Retrieving a Single Model with Eloquent in Laravel
Often you do not want a set of records, you want one. Eloquent gives you a few ways to pull a single model, and a couple of them tie in neatly...
Cost and Performance Optimisation in Laravel Vapor
On Vapor, the building block is AWS Lambda, and that is where your compute bill comes from. Lambda pricing trips people up because it depends...
Job Encryption in Laravel
When you dispatch a job, its payload is stored in plain, serialized text in your queue store. For most jobs that is fine. But if a job carries...
Split a List of Dates into Consecutive Ranges in PHP
A reader asked me how to take a flat list of dates and group them into ranges, where each range is an unbroken run of consecutive days. Wherev...
Conditionally Queueing Event Listeners in Laravel
Queued event listeners are great for moving slow work off the request. But there is an easy way to waste your queue: pushing a listener for ev...
Rendering Exceptions in Laravel
Rendering is the half of exception handling the user does see. Once an exception has been reported, Laravel has to turn it into an actual resp...
Queue Job Batching in Laravel: How It Works
Job batching lets you dispatch a group of jobs to run in parallel across your workers, then run code when the whole group finishes or when one...
Running the Same Queued Job Multiple Times
Sometimes one job needs to run several times, spaced out, until a condition is met. The trick is a job that re-queues itself with release(). L...
Get All Dates Between Two Dates in Laravel
Sometimes you need every individual date between two dates, for example to build a timesheet or a payroll sheet where each day is a column. Ca...
Finding the Nearest Records by GPS Coordinates in Laravel
I built this for a food delivery app. A user opens the app and wants restaurants within, say, one kilometre of where they are standing. The ph...
How Laravel's Notification System Works
Laravel's notification system makes it easy to send the same message to your users across many channels: email, SMS, a database row, a broadca...
Introduction to Redis Hashes
When you find yourself making lots of keys that share a prefix, like shop:42:product:1:sales, shop:42:product:2:sales, and so on, that is Redi...
Using Multiple Database Connections in Laravel
A reader once described a common setup to me: a master database and a replica that copies from it. The default connection points at the master...
CSRF Protection in Laravel
CSRF stands for cross site request forgery. It is an attack where another site tricks a logged in user's browser into sending a request to you...
Working with Polymorphic Relationships in Laravel
Imagine you need documents on several different things in your system: employees, customers, companies. The obvious approach is a separate doc...
Retrieving Models with Eloquent in Laravel
Once you have a model and its table, reading data is easy. Think of every Eloquent model as a query builder pointed at its own table. You can...
Filtering by Relationship Existence with whereHas and whereHasMorph
Often you want records based on something about their related records: posts that have comments, users who have placed an order, comments whos...
Working with Dates and Times in Laravel using Carbon
Dates in plain PHP are awkward: strtotime, format strings, manual maths. Carbon wraps all of that in a clean API, and the good news is that La...