Guardrails for AI-Assisted Development in Laravel
Guardrails have always been an important aspect of software engineering. At the beginning of my career, I was fully focused on developing new features and fixing bugs. But when a new senior joined...
// Category
These posts are about something Laravel related.
Guardrails have always been an important aspect of software engineering. At the beginning of my career, I was fully focused on developing new features and fixing bugs. But when a new senior joined...
When you want to update a record and create it when it doesn't exist, you can use the updateOrCreate or updateOrInsert method in Laravel.
The so-called "upsert" methods....
In Laravel it is seen as good practice to dependency inject the Illuminuate\Http\Request object in your methods when possible, instead of using the request() helper.
One of...
WebP is a modern image format for the web that is developed by Google. It is based on the VP8 video format, and provides superior compression. Because of these qualities, it is intended to replace...
When writing request validators in Laravel, it is useful to know which incoming data will lead to a validation error, and which data will pass. A convenient way to test this, is to write unit tests...
When you want to rollback a set of database operations if one of them fails, you can execute them within a database transaction. Laravel provides several techniques to do this. One of them, that I...
Sometimes, you may end up with a collection that contains null values.
Removing those null values from the collection can be done very smoothly with the filter...
Notifications in Laravel are typically used to notify users in your application.
Users do not have to be the App\Models\User model, but can be any model that includes the...
When working with Laravel, you will probably use the query builder in order to create and run database queries. Sometimes you want to see the raw SQL output of a query, for example when you are...
Since Laravel 8.16, it is possible to split a collection into chunks in two different ways. The first one, that already existed, is the split method: This method breaks a collection into a...
When creating a catch-all route in Laravel, you might encounter conflicts with others routes in your application. In this post I would like to describe how you can resolve some of these conflicts....
When you want to show a list of all registered routes in your application, you can use the php artisan route:list command.
The output of this command can be a bit confusing when you are...
Sometimes you want to call an Artisan command from your code. Some commands show data. How do you read the data that an Artisan command may show in the console? For example, you could have a command...
When you need to update a resource in Laravel, you might decide to use the update or the fill method.
Let's take a look at the source code of the fill and...
Laravel 7 introduced Custom Eloquent Casts. Next to primitive types, such as json, it is also possible to cast values that form a compound to objects. This is an effective way to introduce value...
With configuration caching you can bundle all configuration files, to be loaded faster by Laravel.
When you run php artisan config:cache, a new file will be created in...
Since 7.x, Laravel provides a very compact syntax for creating foreign key constraints with the constrained method.
In this post we will give a short demonstration of this syntax, and we...
Recently I stumbled upon a nested query in a Laravel project. It was written like this: You might have seen a comparable nested query in the code you had to work on, and you probably agree that they...
Laravel 7 came with a new feature, stub customization. Stub customization gives the ability to modify the stub files that are used when creating classes such as controllers and tests with the...
Laravel 7 has an excellent new feature, called fluent string operations. It provides an "object-oriented interface for working with string values", e.g. becomes In this post I would like to...
Elasticsearch is a full-text search engine that is used by organizations such as Cisco, Adobe, eBay, Microsoft and thousands of others. With Elasticsearch you can search large amounts of documents...
The Laravel service container is called "a powerful tool for managing class dependencies and performing dependency injection". In this post, we will look at a possible use case of the service...
In most cases, when writing policies in Laravel, you only pass one argument to a policy method, since the authenticated user is already available through dependency injection and no other resources...
Just recently I discovered you can apply where statements to the unique and exists validation rules in Laravel, without using a closure.
This means you can...
One of the cool things of Laravel's validation rules, is that you can apply certain rules to different data types. When checking the minimum and maximum size of an array, you can use the...