Adldap\Laravel\Traits\ImportsUsers::findOrCreateModelFromAdldap PHP Method

findOrCreateModelFromAdldap() protected method

Finds an Eloquent model from the specified Adldap user.
protected findOrCreateModelFromAdldap ( User $user ) : Model
$user Adldap\Models\User
return Illuminate\Database\Eloquent\Model
    protected function findOrCreateModelFromAdldap(User $user)
    {
        // Get the model key.
        $attributes = $this->getUsernameAttribute();
        // Get the model key.
        $key = key($attributes);
        // Get the username from the AD model.
        $username = $user->{$attributes[$key]};
        // Make sure we retrieve the first username result if it's an array.
        $username = is_array($username) ? array_get($username, 0) : $username;
        // Try to find the local database user record.
        $model = $this->newEloquentQuery($key, $username)->first();
        // Create a new model instance of it isn't found.
        $model = $model instanceof Model ? $model : $this->createModel();
        // Set the username in case of changes in active directory.
        $model->{$key} = $username;
        return $model;
    }