@param \Illuminate\Database\Eloquent\Model|null $instance

@return mixed|null
965270
public function getValues(\Illuminate\Database\Eloquent\Model $instance = null)
    {
        if ($instance) {
            $this->setInstance($instance);
        }
        if ($this->isHandler()) {
            return $this->getHandler();
        }

        if ($this->instance) {
            return $this->getValueColumn($this->instance, $this->key);
        }

        return null;
    }
762347
public function buildObject($instance = null)
    {
        if (is_null($instance)) {
            return (object) $this->fields;
        }
        foreach ($this->fields as $property => $value) {
            $method = 'set' . ucwords($property);
            if (is_callable([$instance, $method])) {
                $instance->{$method}($value);
            }
        }
    }
524572
public static function objectsManager($instance = null)
    {
        if (!$instance) {
            $className = get_called_class();
            $instance = new $className();
        }

        if (class_exists($managerClass = self::getManagerClass())) {
            return new $managerClass($instance, $instance->getConnection());
        }

        return new TreeManager($instance, $instance->getConnection());
    }
538392
public function update_instance($instance, $data) {
        global $DB;
        $properties = array('status', 'name', 'password', 'customint1', 'customint2', 'customint3',
                            'customint4', 'customint5', 'customint6', 'customint7', 'customint8',
                            'customchar1', 'customchar2', 'customchar3', 'customdec1', 'customdec2',
                            'customtext1', 'customtext2', 'customtext3', 'customtext4', 'roleid',
                            'enrolperiod', 'expirynotify', 'notifyall', 'expirythreshold',
                            'enrolstartdate', 'enrolenddate', 'cost', 'currency');

        foreach ($properties as $key) {
            if (isset($data->$key)) {
                $instance->$key = $data->$key;
            }
        }
        $instance->timemodified = time();

        $update = $DB->update_record('enrol', $instance);
        if ($update) {
            \core\event\enrol_instance_updated::create_from_record($instance)->trigger();
        }
        return $update;
    }
1208444
public function instance($abstract, $instance)
    {
        $this->laravel->instance($abstract, $instance);
        $this->callAllListeners($abstract, $instance);

        return $this;
    }
1343828
public static function delete($instance)
	{
		$class = get_called_class();

		if ($instance === true)
		{
			static::$_instances[$class] = array();

			return true;
		}
		elseif (static::exists($instance))
		{
			unset(static::$_instances[$class][$instance]);

			return true;
		}

		return false;
	}
819749
public static function instance($newInstance = null)
    {
        static $instance;

        if ($newInstance instanceof self) {
            $instance = $newInstance;
        }

        if (!($instance instanceof self)) {
            $instance = new self();
        }

        return $instance;
    }
914968
public function get($instanceName) {
		if (!isset($this->objectInstances[$instanceName]) || $this->objectInstances[$instanceName] == null) {
			$this->instantiateComponent($instanceName);
		}
		return $this->objectInstances[$instanceName];
	}
285831
public function getModelInstance()
    {
        if ($this->instance !== null) {
            return $this->instance;
        }
        $model = $this->getModel();
        if ($model === false) {
            return false;
        }
        $instance = new $model();

        return $instance;
    }
1243327
public function delete_instance($instance) {
        global $DB;

        // Get the tool associated with this instance.
        $tool = $DB->get_record('enrol_lti_tools', array('enrolid' => $instance->id), 'id', MUST_EXIST);

        // Delete any users associated with this tool.
        $DB->delete_records('enrol_lti_users', array('toolid' => $tool->id));

        // Get tool and consumer mappings.
        $rsmapping = $DB->get_recordset('enrol_lti_tool_consumer_map', array('toolid' => $tool->id));

        // Delete consumers that are linked to this tool and their related data.
        $dataconnector = new data_connector();
        foreach ($rsmapping as $mapping) {
            $consumer = new ToolConsumer(null, $dataconnector);
            $consumer->setRecordId($mapping->consumerid);
            $dataconnector->deleteToolConsumer($consumer);
        }
        $rsmapping->close();

        // Delete mapping records.
        $DB->delete_records('enrol_lti_tool_consumer_map', array('toolid' => $tool->id));

        // Delete the lti tool record.
        $DB->delete_records('enrol_lti_tools', array('id' => $tool->id));

        // Time for the parent to do it's thang, yeow.
        parent::delete_instance($instance);
    }
237252
public function remove(Instance $instance)
    {
        $key = $this->getHash().$instance->getId();
        if($this->getFileManager()->has($key)) {
            $this->getFileManager()->delete($key);
        }
    }
797588
public function set($name, $instance)
    {
        $key = $this->makeKey($name);

        $this->alias($name, $this->describe(get_class($instance)));

        $this->instances[$key] = $instance;

        return $this;
    }
529256
public function insert($instance, $entity = null)
    {
        list($instance, $entity) = $this->reassignEntity($instance, $entity);

        return new InsertQuery(
            $this->connection,
            $instance,
            $this->models->get($entity),
            $this->factory,
            $this->accessor,
            $this->dispatcher
        );
    }
304011
public static function getInstanceAndConnect() {
		if (!is_object(self::getInstance())) {
			return NULL;
		}
		if (!self::$instance->tryConnect()) {
			return NULL;
		}
		return self::$instance;
	}
440538
protected function getConfigInstance($instance)
    {
        if (is_callable($instance)) {
            return call_user_func($instance, $this->app);
        } elseif (is_string($instance)) {
            return $this->app->make($instance);
        }

        return $instance;
    }
334328
public function isAllowed($instance, $user)
    {
        if ($user) {
            if (!is_string($instance)) {
                if ($instance->admin && $user->admin === false) {
                    return false;
                }
                // El admin tiene acceso a cualquier pagina
                if ($user->admin === 1) {
                    return true;
                }
            }
            $page = new Page();
            $current = $page->get_by_controller($instance);
            if ($current && $current->count() > 0) {
                $result = $this->getByPageUser($user->id, $current->getModel()->id);
                if ($result->count() > 0) {
                    return $result->getModel()->allowed;
                }
            } else {
                return false;
            }
        }

        return true;
    }
826948
public function lazyLoad($instance, $relation_name)
    {
        if (($relation = $this->get($instance, $relation_name)) === false) {
            throw new InvalidValueException($relation);
        }

        $type = $relation->type;
        $referenceModel = $relation->referenceModel;
        $valueField = $relation->valueField;
        if ($type === Relation::TYPE_HAS_ONE) {
            return $referenceModel::query()->whereEq($relation->keyField, $instance->$valueField)->setFetchType(false);
        } elseif ($type === Relation::TYPE_BELONGS_TO) {
            return $referenceModel::query()->whereEq($relation->keyField, $instance->$valueField)->setFetchType(false);
        } elseif ($type === Relation::TYPE_HAS_MANY) {
            return $referenceModel::query()->whereEq($relation->keyField, $instance->$valueField)->setFetchType(true);
        } elseif ($type === Relation::TYPE_HAS_MANY_TO_MANY) {
            $ids = $instance::values($relation->keyField, [$valueField => $instance->$valueField]);
            /** @var \ManaPHP\Model $referenceInstance */
            $referenceInstance = is_string($referenceModel) ? new $referenceModel : $referenceModel;
            return $referenceModel::query()->whereIn($referenceInstance->getPrimaryKey(), $ids)->setFetchType(true);
        } elseif ($type === Relation::TYPE_HAS_MANY_VIA) {
            $via = $relation->keyField;
            /** @var \ManaPHP\Model $reference */
            $reference = new $referenceModel();
            $ids = $via::values($reference->getPrimaryKey(), [$valueField => $instance->$valueField]);
            return $referenceModel::query()->whereIn($reference->getPrimaryKey(), $ids)->setFetchType(true);
        } else {
            throw  new NotSupportedException(['unknown relation type: :type', 'type' => $type]);
        }
    }