Laravel Check If Object Has Property Example
Hi Guys,
In this example,I will learn you how to use property exist or isset method in laravel.you can easy and simply use method in laravel.
Example 1 :
Syntax :
isset( mixed $var [, mixed $... ] )
public function index(User $user)
{
$user = User::where('id',1)->first();
if (isset($user->birth_date)){
dd('True');
}else{
dd('false');
}
}
-> isset return True then exists colume in table.
-> isset return False then not exists colume in table.
Output :
True
Example 2 :
Syntax :
property_exists(object, property)
public function index(User $user)
{
$user = User::where('id',1)->first();
if (property_exists($user,'birth_date')){
dd('True');
}else{
dd('false');
}
}
The property_exists() function returns TRUE if the property exists, FALSE if it doesn't exist or NULL in case of an error.
Output :
True
It will help you...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial