Checking For Null Values In A User Object

- 1 answer

is it possible to check for null values in an object in Laravel? I want to check if a user has completed their profile when they hit an api endpoint so that I can let them know they need to complete their profile if there is a field with null values.

This is how the user object will look like

    id: 8,
    name: "Jim Jam",
    username: "[email protected]",
    email_verified_at: null,
    dob: null,
    sex: null,
    nationality: null,
    address: null,
    state: null,
    country: null,
    phone: null,
    created_at: "2019-08-03 21:10:20",
    updated_at: "2019-08-03 21:10:20",

Tried this is_null($user->sex || $user->phone) but it returned false.

What are the possible ways to check if a field is null?



If you want to check a few variables you should check each variable separately. For exampe:

is_null($user->sex) || is_null($user->phone)