How to check if variable is empty in laravel?

by raphael_tillman , in category: PHP Frameworks , 6 months ago

How to check if variable is empty in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elisha_langworth , 6 months 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.