@param \ManaPHP\Model          $model
@param                         $name
@param                         $data

@return \ManaPHP\QueryInterface
764562
public function getQuery($model, $name, $data)
    {
        $relation = $this->get($model, $name);
        /** @var \ManaPHP\Model $referenceModel */
        $referenceModel = $relation->referenceModel;
        $query = $referenceModel::query();

        if ($data === null) {
            null;
        } elseif (is_string($data)) {
            $query->select($data);
        } elseif (is_array($data)) {
            if ($data) {
                if (isset($data[count($data) - 1])) {
                    $query->select(count($data) > 1 ? $data : $data[0]);
                } elseif (isset($data[0])) {
                    $query->select($data[0]);
                    unset($data[0]);
                    $query->where($data);
                } else {
                    $query->where($data);
                }
            }
        } elseif (is_callable($data)) {
            $query = $data($query);
        } else {
            throw new InvalidValueException(['`:with` with is invalid', 'with' => $name]);
        }

        return $query;
    }
1328884
private function setFromEloquent($model, string $name, string $key)
    {
        $options = $model->pluck($name, $key);

        $this->set('options', $options);

        $this->addBeforeRender(function () {
            $value = [];

            collect($this->get('value'))->each(function ($item) use (&$value) {
                if (is_object($item)) {
                    $value[$item->id] = $item->name;
                } else {
                    $value[] = $item;
                }
            });

            $this->set('value', $value);
        });

        return $this;
    }
1049904
public function routeModel( $name, $model, $parameters = [], $absolute = true )
	{
		if ( !$model instanceof RoutableModel )
			throw new UrlGenerationException( "The model [" . get_class( $model ) . "] must implement the RoutableModel interface." );

		if ( !is_null( $route = $this->routes->getByName( $name ) ) )
		{
			$appendedUrl = "";

			if ( is_array( $p = $model->appendRoute( $name, $parameters, $appendedUrl ) ) )
				$parameters = array_merge( $parameters, $p );

			return $this->toRoute( $route, $parameters, $absolute ) . $appendedUrl;
		}

		throw new RouteNotFoundException( "Route [{$name}] not found." );
	}
164684
public function getView($name, $data = [])
    {
        $view = 'missing-page';

        if (view()->exists('page::' . $name)) {
            $view = $name;
        }

        return view('page::' . $view, $data);
    }
780267
public function getModel($table, $name, $value)
    {
        //get the row
        $result = $this->getRow($table, $name, $value);

        if (is_null($result)) {
            return null;
        }

        return $this->model()->setTable($table)->set($result);
    }
1012016
public function searchByNameAndType($name = null, $type = null)
    {
        $searchResult = $this->getRequest()->request(
            'POST',
            $this->getRequestUrl('models/searches'),
            [
                'model_query' => [
                    'name' => $name,
                    'type' => $type,
                ],

            ]
        );

        return $this->getModelsFromResult($searchResult);
    }
1223159
public function fromModel($model, string $name, string $key = null): self
    {
        /* @var $model Model */
        $model = is_object($model) ? $model : new $model();
        $key = $key ?? $model->getModel()->getKeyName();

        return $this->setFromEloquent($model, $name, $key);
    }
1310039
public function resolve($name, $format, array $data, $method = 'compose')
    {
        $parser = $this->parse($name);
        $format = $format ?? $this->getPrefersFor($parser);

        return $parser->compose($format, $data, $method);
    }
759284
public function required($name, $data = null)
	{
		if (null === $data)
		{
			return isset($this->data[$name]);
		}
		else
		{
			return isset($data[$name]);
		}
	}
1311643
protected function view($name, array $data = [])
    {
        $this->viewExistsOrFail($name);

        $this->data = array_merge($this->data, $data);

        $this->beforeViewRender();
        $view = $this->renderView($name);
        $this->afterViewRender();

        return $view;
    }
795051
public function update($model, array $data = [])
    {
        $this->setModelData($model, $data);

        return $this->saveForUpdate($model);
    }
1028543
public static function make($name, $data = null, $nest = null)
    {
        self::$view = new Views();

        return self::$view->call($name, $data, $nest);
    }
1215351
public function getProperty($name)
    {
        if ($this->hasProperty($name)) {
            return $this->properties[$name];
        }
        throw new ModelException(
            'Property ' . $name . ' does not exist.'
        );
    }
589579
protected function fill(Model $model, object $data): Model
    {
        $mapper = new ObjectMapper();

        return $mapper->map($model)->fill($data);
    }
294836
protected function deleteModel($model_name, $id)
    {
        /*
         * Retrieve the desired model
         */
        $response = $this->delete('warden::api.delete-model', [$model_name, $id]);

        Session::flash('message', 'Hooray! It worked! The model was deleted!');

        return redirect(route('warden::models', $model_name));
    }
1278060
protected function getModelValueAttribute($model, $name)
    {
        $transformedName = $this->transformKey($name);
        if (is_string($model)) {
            return $model;
        } elseif (is_object($model)) {
            return object_get($model, $transformedName);
        } elseif (is_array($model)) {
            return array_get($model, $transformedName);
        }
    }
1004697
public function triggerModels($name, ModelEvent $event = null)
    {
        if ($event === null) {
            $event = new ModelEvent();
        }
        foreach ($this->models as $model) {
            $model->trigger($name, $event);
        }

        return $event->isValid;
    }