예제 #1
0
 /**
  * MorphToMany constructor.
  * @param \Notadd\Foundation\Database\Eloquent\Builder $query
  * @param \Notadd\Foundation\Database\Eloquent\Model $parent
  * @param string $name
  * @param string $table
  * @param string $foreignKey
  * @param string $otherKey
  * @param string $relationName
  * @param bool $inverse
  */
 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);
 }
예제 #2
0
 /**
  * @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([$this->query, 'where'], func_get_args());
     }
     return $this;
 }
 /**
  * @return void
  */
 public function register()
 {
     Model::clearBootedModels();
     $this->registerEloquentFactory();
     $this->registerQueueableEntityResolver();
     $this->app->singleton('db.factory', function ($app) {
         return new ConnectionFactory($app);
     });
     $this->app->singleton('db', function ($app) {
         return new DatabaseManager($app, $app['db.factory']);
     });
     $this->app->bind('db.connection', function ($app) {
         return $app['db']->connection();
     });
 }
예제 #4
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Model $model
  * @return $this
  */
 public function setModel(Model $model)
 {
     $this->model = $model;
     $this->query->from($model->getTable());
     return $this;
 }
예제 #5
0
 /**
  * @return bool
  */
 public function hasParent()
 {
     return $this->getAttribute('parent_id') && parent::whereId($this->getAttribute('parent_id'))->count();
 }
예제 #6
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Model $model
  * @param array $joining
  * @param bool $touch
  * @return \Notadd\Foundation\Database\Eloquent\Model
  */
 public function save(Model $model, array $joining = [], $touch = true)
 {
     $model->save(['touch' => false]);
     $this->attach($model->getKey(), $joining, $touch);
     return $model;
 }
예제 #7
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Model $model
  * @return \Notadd\Foundation\Database\Eloquent\Model
  */
 public function associate($model)
 {
     $this->parent->setAttribute($this->foreignKey, $model->getKey());
     $this->parent->setAttribute($this->morphType, $model->getMorphClass());
     return $this->parent->setRelation($this->relation, $model);
 }
예제 #8
0
 /**
  * @param int $parent_id
  * @return static
  */
 public function getSubCategories($parent_id = 0)
 {
     if (!$parent_id) {
         $parent_id = $this->attributes['id'];
     }
     $count = parent::whereEnabled(true)->whereParentId($parent_id)->count();
     if ($count) {
         return parent::whereEnabled(true)->whereParentId($parent_id)->get();
     } else {
         return Collection::make();
     }
 }
예제 #9
0
 /**
  * @param array $attributes
  * @return \Notadd\Foundation\Database\Eloquent\Model
  */
 protected function makeInstance(array $attributes = [])
 {
     return Model::unguarded(function () use($attributes) {
         if (!isset($this->definitions[$this->class][$this->name])) {
             throw new InvalidArgumentException("Unable to locate factory with name [{$this->name}] [{$this->class}].");
         }
         $definition = call_user_func($this->definitions[$this->class][$this->name], $this->faker, $attributes);
         return new $this->class(array_merge($definition, $attributes));
     });
 }
예제 #10
0
 /**
  * @return string
  */
 public function getHasCompareKey()
 {
     return $this->farParent->getQualifiedKeyName();
 }
예제 #11
0
 /**
  * @return mixed
  */
 public function getSubMenus()
 {
     return parent::whereEnabled(true)->whereGroupId($this->attributes['group_id'])->whereParentId($this->attributes['id'])->orderBy('order_id')->get();
 }
예제 #12
0
 /**
  * @return string
  */
 public function getUpdatedAtColumn()
 {
     return $this->parent->getUpdatedAtColumn();
 }
예제 #13
0
 /**
  * Bootstrap Eloquent so it is ready for usage.
  * @return void
  */
 public function bootEloquent()
 {
     Eloquent::setConnectionResolver($this->manager);
     if ($dispatcher = $this->getEventDispatcher()) {
         Eloquent::setEventDispatcher($dispatcher);
     }
 }
예제 #14
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Model $model
  * @return \Notadd\Foundation\Database\Eloquent\Model
  */
 public function save(Model $model)
 {
     $model->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
     return $model->save() ? $model : false;
 }
예제 #15
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Model|int $model
  * @return \Notadd\Foundation\Database\Eloquent\Model
  */
 public function associate($model)
 {
     $otherKey = $model instanceof Model ? $model->getAttribute($this->otherKey) : $model;
     $this->parent->setAttribute($this->foreignKey, $otherKey);
     if ($model instanceof Model) {
         $this->parent->setRelation($this->relation, $model);
     }
     return $this->parent;
 }
예제 #16
0
 /**
  * @param string $value
  * @return string
  */
 public function wrap($value)
 {
     return $this->parent->newQueryWithoutScopes()->getQuery()->getGrammar()->wrap($value);
 }
예제 #17
0
 /**
  * @param \Notadd\Foundation\Database\Eloquent\Model $model
  * @return \Notadd\Foundation\Database\Eloquent\Model
  */
 public function save(Model $model)
 {
     $model->setAttribute($this->getPlainMorphType(), $this->morphClass);
     return parent::save($model);
 }