Ad
Checking For Null Values In A User Object
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?
Ad
Answer
If you want to check a few variables you should check each variable separately. For exampe:
is_null($user->sex) || is_null($user->phone)
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad