I've done some googling on this and can't seem to find much assistance. However, I was wondering if there is a way to check multiple Instance types for an argument in a function, so to check whether it is an instance of the User model or another model for example and if it is one of the two then allow it through. If not, throw an error. I am using PHP and Laravel.
The use case here is that I am migrating a database from SQL to Mongo, so for an interim period I'll have two user models (User
and MongoUser
) and I want to check against each of these to determine whether the argument is a User instance of some form.
public function setTo(User $user)
{
$this->user()->associate($user);
return $this;
}
Last resort, I can duplicate the functions, but this seems unnecessary duplication. And I'd rather not remove the Instance check altogether.
I wanted to know if there was a way to achieve this? If not, I'd be interested to hear people's thoughts on the best way to handle this generally.
Thanks!