This laravel quick tutorial helps to understand Laravel collection is empty or not. The laravel collection is used to store data with arrays of data. The collections are immutable, which Means every Collection method returns an entirely new Collection instance.
Immutable collections can’t be changed at all. They have their own elements. The laravel collection will have two methods to check collection is empty or not.
You can also check other recommended tutorials of Lumen/Laravel,
You can use these methods with any version laravel 8 and laravel 9 applications. I will give you simple examples of isEmpty()
and isNotEmpty()
collection in laravel.
Let’s take a simple collection example to check is empty or not using isEmpty() method.
$collecton->isEmpty();
public function index() { $collection = collect([]); $res = $collection->isEmpty(); }
Output:
true
Let’s check laravel collection is not empty using isNotEmpty()
method.
$collecton->isNotEmpty();
public function index() { $collection = collect([]); $output = $collection->isNotEmpty(); }
Output:
false
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More