/** * Bootstrap the Application events. * * @return void */ public function boot() { $db = $this->app['db']; $events = $this->app['events']; // Setup the ORM Model. Model::setConnectionResolver($db); Model::setEventDispatcher($events); // Setup the (basic) Model. BasicModel::setConnectionResolver($db); // Setup the legacy Database Helper. Database::setConnectionResolver($db); }
/** * Create a new has many relationship instance. * * @param \Database\ORM\Builder $query * @param \Database\ORM\Model $parent * @param string $name * @param string $table * @param string $foreignKey * @param string $otherKey * @param string $relationName * @param bool $inverse * @return void */ public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false) { $this->inverse = $inverse; $this->morphType = $name . '_type'; $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass(); parent::__construct($query, $parent, $table, $foreignKey, $otherKey, $relationName); }
/** * Add a basic where clause to the query. * * @param string $column * @param string $operator * @param mixed $value * @param string $boolean * @return $this */ public function where($column, $operator = null, $value = null, $boolean = 'and') { if ($column instanceof Closure) { $query = $this->model->newQueryWithoutScopes(); call_user_func($column, $query); $this->query->addNestedWhereQuery($query->getQuery(), $boolean); } else { call_user_func_array(array($this->query, 'where'), func_get_args()); } return $this; }
/** * Set a model instance for the model being queried. * * @param \Database\ORM\Model $model * @return $this */ public function setModel(Model $model) { $this->model = $model; $this->query->from($model->getTable()); return $this; }
/** * Save a new model and attach it to the parent model. * * @param \Database\ORM\Model $model * @param array $joining * @param bool $touch * @return \Database\ORM\Model */ public function save(Model $model, array $joining = array(), $touch = true) { $model->save(array('touch' => false)); $this->attach($model->getKey(), $joining, $touch); return $model; }
/** * Attach a model instance to the parent model. * * @param \Database\ORM\Model $model * @return \Database\ORM\Model */ public function save(Model $model) { $model->setAttribute($this->getPlainMorphType(), $this->morphClass); return parent::save($model); }
/** * Wrap the given value with the parent query's grammar. * * @param string $value * @return string */ public function wrap($value) { return $this->parent->newQueryWithoutScopes()->getQuery()->getGrammar()->wrap($value); }
/** * Get the name of the "updated at" column. * * @return string */ public function getUpdatedAtColumn() { return $this->parent->getUpdatedAtColumn(); }
/** * Associate the model instance to the given parent. * * @param \Database\ORM\Model $model * @return \Database\ORM\Model */ public function associate(Model $model) { $this->parent->setAttribute($this->foreignKey, $model->getKey()); $this->parent->setAttribute($this->morphType, $model->getMorphClass()); return $this->parent->setRelation($this->relation, $model); }
/** * Attach a model instance to the parent model. * * @param \Database\ORM\Model $model * @return \Database\ORM\Model */ public function save(Model $model) { $model->setAttribute($this->getPlainForeignKey(), $this->getParentKey()); return $model->save() ? $model : false; }
/** * Associate the model instance to the given parent. * * @param \Database\ORM\Model $model * @return \Database\ORM\Model */ public function associate(Model $model) { $this->parent->setAttribute($this->foreignKey, $model->getAttribute($this->otherKey)); return $this->parent->setRelation($this->relation, $model); }
/** * Get the key for comparing against the parent key in "has" query. * * @return string */ public function getHasCompareKey() { return $this->farParent->getQualifiedKeyName(); }