コード例 #1
4
 /**
  * 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);
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
 /**
  * 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;
 }
コード例 #6
0
 /**
  * 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);
 }
コード例 #7
0
 /**
  * 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);
 }
コード例 #8
0
 /**
  * Get the name of the "updated at" column.
  *
  * @return string
  */
 public function getUpdatedAtColumn()
 {
     return $this->parent->getUpdatedAtColumn();
 }
コード例 #9
0
 /**
  * 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);
 }
コード例 #10
0
 /**
  * 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;
 }
コード例 #11
0
 /**
  * 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);
 }
コード例 #12
0
 /**
  * Get the key for comparing against the parent key in "has" query.
  *
  * @return string
  */
 public function getHasCompareKey()
 {
     return $this->farParent->getQualifiedKeyName();
 }