I want to check if there is a function in laravel 8 like IsNullOrEmpty for C# to check for empty and null value using just one function.
Asked
Active
Viewed 4,556 times
0
-
You can use ``empty()`` You can provide some codes that you have tried so far? – Sok Chanty Nov 18 '20 at 10:41
1 Answers
2
you can use empty()
PHP function.
The empty()
function checks whether a variable is empty or not.
This function returns false if the variable exists and is not empty, otherwise it returns true.
The following values evaluates to empty:
- 0
- 0.0
- "0"
- ""
- FALSE
- array()
- NULL

Shahzaib Anwar Rehmani
- 61
- 1
- 7
-
But when you use eloquent get() function, empty() will not work. empty() returns true for collection and laravel eloquent get() return collection of objects. In this scenario you will have to use collection's isEmpty() or isNotEmpty() functions. – Masood Khan Nov 18 '20 at 15:06