Laravel Collection isEmpty() and isNotEmpty() Method Example

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

This article will provide lesson of laravel collection check if empty. We will use laravel check collection is not empty. i would like to share with you check if collection is empty in laravel. This article will give you simple lesson of check laravel collection empty. Let's see bellow lesson laravel collection empty check.

I will give you simple lessons of isEmpty and isNotEmpty colletion in laravel. so you can easily use it with your laravel 5, laravel 6, laravel 7 and laravel 8 application. so let's see bellow lesson that will helps you lot.

Laravel Collection isEmpty() Example

Syntax:

$collecton->isEmpty();

Example

public function index()

{

$collection = collect([]);

$output = $collection->isEmpty();

}

Result:-

true

Laravel Collection isNotEmpty() Example

Syntax:

$collecton->isNotEmpty();

Example

public function index()

{

$collection = collect([]);

$output = $collection->isNotEmpty();

}

Result:-

false

thank you very much for following up with me.

Recent Posts

Related Posts