Just released! Manage your Laravel projects with Invoker. The no-bull Laravel admin panel.

PHP

These posts are about a subject that involves PHP.

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

November 25, 2020

How to Split a Collection in Laravel 8

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

Read

November 16, 2020

Excluding Routes From a Catch-All Route by Using Regex in Laravel

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

Read

October 1, 2020

Practical Options for the Route List Command in Laravel

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

Read

September 1, 2020

How To Get The Output Of An Artisan Command When Called Programmatically?

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

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

June 17, 2020

Configuration Caching Caveats in Laravel

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

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

April 19, 2020

How to Use Stub Customization in Laravel

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

Read

March 29, 2020

Run Tests With PHP Artisan Test

Since the release of Laravel 7.x, you can run you tests by executing as an alternative to running your tests with the phpunit command. This command will run all your tests, until the...

Read

March 11, 2020

How to Use Fluent String Operations in Laravel 7

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

Read

February 27, 2020

How to Ignore PHPCS Warnings

PHP_CodeSniffer is a useful tool to check your code against a set of standards and rules. It can help in securing a certain coding standard and style within a development team, by running PHPCS as a...

Read

February 21, 2020

Run Elasticsearch With Laravel on MacOS

A guide on how to install Elasticsearch on MacOS in order to use it as a driver for Laravel Scout

Read

February 1, 2020

Binding API Connection Interfaces To Implementations in The Laravel Container

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

Read

January 23, 2020

Passing Multiple Arguments To Laravel Policy Methods

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

Read

December 20, 2019

Using The Where Clause in Validation Rules

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

Read

December 15, 2019

Validating Array Lengths in Laravel

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

Read

Sign up for the newsletter