Database

These posts contain subjects related to databases.

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....

Read

October 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

February 11, 2021

Six Ways to Get Raw SQL Output From Query Builder in Laravel

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...

Read

August 18, 2020

What Are The Differences Between Update And Fill in Laravel?

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...

Read

July 8, 2020

What is Value Object Casting in Laravel?

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...

Read

May 16, 2020

A New Syntax For Foreign Keys in Laravel 7

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...

Read

April 24, 2020

Refactoring Nested Queries in Laravel With Dot Notation And Arrow Functions

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...

Read

Sign up for the newsletter