PHP Class illuminate\database\eloquent\relations\ BelongsTo Code Examples

PHP illuminate\database\eloquent\relations\BelongsTo - 12 examples found. These are the top rated real world PHP examples of class illuminate\database\eloquent\relations\BelongsTo extracted from open source projects. You can rate examples to help us improve the quality of examples
Inheritance: extends Illuminate\Database\Eloquent\Relations\Relation
Example #1
3
 /**
  * @param QueryBuilder $builder
  * @param $data
  *
  * @return void
  */
 public function applyFilterConstraint(QueryBuilder $builder, $data)
 {
     if (empty($data)) {
         return;
     }
     $builder->whereIn($this->relation->getForeignKey(), explode(',', $data));
 }
Example #2
1
 /**
  * Create a new belongs to relationship instance.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $parent
  * @param  string  $foreignKey
  * @param  string  $otherKey
  * @param  string  $type
  * @param  string  $relation
  * @return void
  */
 public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $type, $relation)
 {
     $this->morphType = $type;
     parent::__construct($query, $parent, $foreignKey, $otherKey, $relation);
 }
 protected function joinBelongsToRelation(Relations\BelongsTo $relation, $type)
 {
     $table = $relation->getRelated()->getTable();
     $foreignKey = $relation->getQualifiedForeignKey();
     $localKey = $relation->getQualifiedOtherKeyName();
     $this->query->join($table, $foreignKey, '=', $localKey, $type);
 }
Example #4
1
 protected function applyBelongsTo(Query $query, Model $model, BelongsTo $belongsTo, $name)
 {
     if (isset($this->joinClasses[$name])) {
         return;
     }
     $modelTable = '';
     // If the table has already an alias
     if (str_contains($name, '.')) {
         $path = explode('.', $name);
         array_pop($path);
         $parentPath = implode('.', $path);
         if (isset($this->joinAliases[$parentPath])) {
             $modelTable = $this->joinAliases[$parentPath];
         }
     }
     if (!$modelTable) {
         $modelTable = $belongsTo->getParent()->getTable();
     }
     $related = $belongsTo->getRelated();
     $relatedTable = $related->getTable();
     $foreignKey = $belongsTo->getForeignKey();
     $otherKey = $belongsTo->getOtherKey();
     $alias = $this->joinNameToAlias($name);
     $joinMethod = $this->getJoinMethod($name);
     $query->{$joinMethod}("{$relatedTable} AS {$alias}", "{$modelTable}.{$foreignKey}", '=', "{$alias}.{$otherKey}");
     $query->distinct();
     $this->addQueryColumn("{$modelTable}.{$foreignKey}");
     $this->joinClasses[$name] = $belongsTo->getRelated();
     $this->joinTable[$name] = $relatedTable;
     $this->joinAliases[$name] = $alias;
 }
Example #5
0
 /**
  * Handle dynamic method calls to the relationship.
  *
  * @param string $method
  * @param array  $parameters
  *
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     $result = parent::__call($method, $parameters);
     if ($method !== 'get') {
         call_user_func_array([$this->fallbackQuery, $method], $parameters);
     }
     return $result;
 }
 private function generateNullConditionFromBelongsTo(BelongsTo $relation)
 {
     $this->query = $this->query->whereNull($relation->getQualifiedOtherKeyName());
 }
Example #7
0
 /**
  * Add an object through a BelongsTo relation
  *
  * @param \Illuminate\Database\Eloquent\Relations\BelongsTo $relation
  * @param \Illuminate\Database\Eloquent\Model $model
  * @return bool
  */
 protected function addBelongsToAssociatedObject(BelongsTo $relation, \Illuminate\Database\Eloquent\Model $model)
 {
     $relation->associate($model);
     return $this->save();
 }
Example #8
0
 /**
  * Handle dynamic method calls to the relationship.
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     try {
         return parent::__call($method, $parameters);
     } catch (BadMethodCallException $e) {
         $this->macroBuffer[] = compact('method', 'parameters');
         return $this;
     }
 }
Example #9
0
 /**
  * Makes a raw where condition string from a BelongsTo relation instance.
  *
  * @param BelongsTo $relation
  * @return string
  */
 protected function getConditionStringFromBelongsTo(BelongsTo $relation)
 {
     $id = $this->getAttribute($relation->getForeignKey());
     // an empty foreign key will, as a null-scope, remove the item from any list
     if (null === $id) {
         return null;
     }
     return '`' . $relation->getForeignKey() . '` = ' . (int) $id;
 }
Example #10
0
 public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $relationName)
 {
     $this->relationName = $relationName;
     parent::__construct($query, $parent, $foreignKey, $otherKey, $relationName);
 }
Example #11
0
 public static function setBelongsTo(BelongsTo $belongsTo, $object = null)
 {
     return $object ? $belongsTo->associate($object) : $belongsTo->dissociate();
 }
Example #12
0
 /**
  * Add select with alias to query from "belongs to" relation
  *
  * @param Builder   $query
  * @param BelongsTo $relatedModel
  */
 private function addBelongsToSelect(Builder $query, BelongsTo $relatedModel)
 {
     $query->getQuery()->join($relatedModel->getRelated()->getTable(), $relatedModel->getQualifiedForeignKey(), '=', $relatedModel->getQualifiedOtherKeyName());
 }