How to check if variable is empty in laravel?

by raphael_tillman , in category: PHP Frameworks , a year ago

How to check if variable is empty in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elisha_langworth , a year ago

@raphael_tillman 

In Laravel, you can check if a variable is empty using the empty function or the isset function.


Using empty function:

1
2
3
4
5
6
7
if(empty($variable)) {
    // variable is empty
    echo "Variable is empty";
} else {
    // variable is not empty
    echo "Variable is not empty";
}


Using isset function:

1
2
3
4
5
6
7
if(isset($variable)) {
    // variable is not empty
    echo "Variable is not empty";
} else {
    // variable is empty
    echo "Variable is empty";
}


You can use either of these methods to determine if a variable is empty or not in Laravel.

Related Threads:

How to check if a variable is empty in PHP?
How to declare an empty variable inside function in php?
How to check iframe is empty?
How to check if date is empty in vuetify?
How to check if an associative array is empty in powershell?
How to check if a variable is set in PHP?