In this tutorial, we will learn, Laravel Check If Object Has Property Example


In this example, you will know how to use the property exist or isset method in Laravel


Example 1 :

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.

Example 2 :


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.


May this example help you.