Kartsa
233
2
Laravel

Checking if Laravel model property is set?

Posted 10 months ago by Kartsa

Is there any way to check if a certain field in a Laravel model object is set?

Consider the following situation created in tinker:

>>> $user = new App\User;
=> App\User {#3035}

>>> $user->email = '[email protected]';
=> "[email protected]"

>>> $user->name = null;
=> null

>>> $user;
=> App\User {#3035
     email: "[email protected]",
     name: null,
   }

>>> $user->email;
=> "[email protected]"

>>> $user->name;
=> null

>>> $user->password;
=> null

$user->name is set, but $user->password is not, but both return null. How can I distinguish these from each other? isset() or property_exists() do not.

Please sign in or create an account to participate in this conversation.