Ejemplo n.º 1
0
 /**
  * Create a new has many relationship instance.
  *
  * @param  \Nova\Database\ORM\Builder  $query
  * @param  \Nova\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);
 }
Ejemplo n.º 2
0
 /**
  * Run the Database Seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call('App\Modules\Users\Database\Seeds\FoobarTableSeeder');
     $this->call('App\\Modules\\Users\\Database\\Seeds\\RolesTableSeeder');
     $this->call('App\\Modules\\Users\\Database\\Seeds\\UsersTableSeeder');
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 /**
  * Save a new model and attach it to the parent model.
  *
  * @param  \Nova\Database\ORM\Model  $model
  * @param  array  $joining
  * @param  bool   $touch
  * @return \Nova\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;
 }
Ejemplo n.º 6
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call('UserTableSeeder');
 }
Ejemplo n.º 7
0
 /**
  * Run the Database Seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call('App\Modules\System\Database\Seeds\FoobarTableSeeder');
 }
Ejemplo n.º 8
0
 /**
  * Attach a model instance to the parent model.
  *
  * @param  \Nova\Database\ORM\Model  $model
  * @return \Nova\Database\ORM\Model
  */
 public function save(Model $model)
 {
     $model->setAttribute($this->getPlainMorphType(), $this->morphClass);
     return parent::save($model);
 }
Ejemplo n.º 9
0
 /**
  * Associate the model instance to the given parent.
  *
  * @param  \Nova\Database\ORM\Model  $model
  * @return \Nova\Database\ORM\Model
  */
 public function associate(Model $model)
 {
     $this->parent->setAttribute($this->foreignKey, $model->getAttribute($this->otherKey));
     return $this->parent->setRelation($this->relation, $model);
 }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 11
0
 /**
  * Get the name of the "updated at" column.
  *
  * @return string
  */
 public function getUpdatedAtColumn()
 {
     return $this->parent->getUpdatedAtColumn();
 }
Ejemplo n.º 12
0
 /**
  * Get the key for comparing against the parent key in "has" query.
  *
  * @return string
  */
 public function getHasCompareKey()
 {
     return $this->farParent->getQualifiedKeyName();
 }
Ejemplo n.º 13
0
 /**
  * Attach a model instance to the parent model.
  *
  * @param  \Nova\Database\ORM\Model  $model
  * @return \Nova\Database\ORM\Model
  */
 public function save(Model $model)
 {
     $model->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
     return $model->save() ? $model : false;
 }
Ejemplo n.º 14
0
 /**
  * Set a model instance for the model being queried.
  *
  * @param  \Nova\Database\ORM\Model  $model
  * @return $this
  */
 public function setModel(Model $model)
 {
     $this->model = $model;
     $this->query->from($model->getTable());
     return $this;
 }
Ejemplo n.º 15
0
 /**
  * Associate the model instance to the given parent.
  *
  * @param  \Nova\Database\ORM\Model  $model
  * @return \Nova\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);
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     SimpleModel::setConnectionResolver($this->app['db']);
     Model::setConnectionResolver($this->app['db']);
     Model::setEventDispatcher($this->app['events']);
 }