November 21, 2023
The Differences Between UpdateOrCreate And UpdateOrInsert in Laravel
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.
I've always wondered what the exact differences are, and...
October 25, 2023
Mock Request Dependency in Laravel
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 the benefits of dependency injection is that it makes...
October 24, 2023
Replace Multiple Items From String Text in PHP With Array
In this post I just want to show a very small trick I came across recently.
You probably know the internal PHP function str_replace
.
When looking at the documentation, we can see...
October 20, 2023
Using and Converting the WebP Image Format in your Laravel Project
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...
ReadSeptember 12, 2022
How To Use Dataproviders When Testing Request Validators In Laravel
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...
ReadFebruary 18, 2022
How To Search And View The Data Of An Elasticsearch Index
When working with Elasticsearch, you might want to know what data is actually stored on an index. This article describes some endpoints of the Elasticsearch REST APIs that might help you during...
ReadNovember 10, 2021
Refactoring Multiple If Statements to Objects
In this article I would like to describe how you can refactor a method that contains multiple if-statements by creating objects with a single responsibility, each making their own assertions. Most...
ReadOctober 26, 2021
Database Transactions in Laravel with saveOrFail, updateOrFail, and deleteOrFail
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...
Read