Laravel Check If Object Has Property Example

10-Apr-2023

.

Admin

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...

#Jqury UI