I have little confusion around how to check the $user is a user object in laravel, what my requirement is if the $user is an object of user then it should run inside the if condition ,please help me to fix this
$user = Apiato::call('User@FindUsersbytask', [$request->id]);
if($user) // here i have to check weather the $user is a user object or not
Apiato::call('User@deleteuserTask', [$request->id]);
CodePudding user response:
Try this way
if(is_object($user))
CodePudding user response:
If what you want is to make sure the variable $user
is an instance of the class User
, then:
if ($user instanceof User) {
...
}
Otherwise, if it's just supposed to be any object, then you can use:
if (is_object($user)) {
...
}
although this will be true for an instance of any object, so you can't safely call methods or access properties that are present on the User
class, for example.