⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.45
Server IP:
185.238.29.86
Server:
Linux server2 6.8.12-6-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-6 (2024-12-19T19:05Z) x86_64
Server Software:
nginx/1.18.0
PHP Version:
8.1.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
work
/
vendor
/
kalnoy
/
nestedset
/
src
/
Edit File: BaseRelation.php
<?php namespace Kalnoy\Nestedset; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Query\Builder; use InvalidArgumentException; abstract class BaseRelation extends Relation { /** * @var QueryBuilder */ protected $query; /** * @var NodeTrait|Model */ protected $parent; /** * The count of self joins. * * @var int */ protected static $selfJoinCount = 0; /** * AncestorsRelation constructor. * * @param QueryBuilder $builder * @param Model $model */ public function __construct(QueryBuilder $builder, Model $model) { if ( ! NestedSet::isNode($model)) { throw new InvalidArgumentException('Model must be node.'); } parent::__construct($builder, $model); } /** * @param Model $model * @param $related * * @return bool */ abstract protected function matches(Model $model, $related); /** * @param QueryBuilder $query * @param Model $model * * @return void */ abstract protected function addEagerConstraint($query, $model); /** * @param $hash * @param $table * @param $lft * @param $rgt * * @return string */ abstract protected function relationExistenceCondition($hash, $table, $lft, $rgt); /** * @param EloquentBuilder $query * @param EloquentBuilder $parent * @param array $columns * * @return mixed */ public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilder $parent, $columns = [ '*' ] ) { $query = $this->getParent()->replicate()->newScopedQuery()->select($columns); $table = $query->getModel()->getTable(); $query->from($table.' as '.$hash = $this->getRelationCountHash()); $query->getModel()->setTable($hash); $grammar = $query->getQuery()->getGrammar(); $condition = $this->relationExistenceCondition( $grammar->wrapTable($hash), $grammar->wrapTable($table), $grammar->wrap($this->parent->getLftName()), $grammar->wrap($this->parent->getRgtName())); return $query->whereRaw($condition); } /** * Initialize the relation on a set of models. * * @param array $models * @param string $relation * * @return array */ public function initRelation(array $models, $relation) { return $models; } /** * Get a relationship join table hash. * * @param bool $incrementJoinCount * @return string */ public function getRelationCountHash($incrementJoinCount = true) { return 'nested_set_'.($incrementJoinCount ? static::$selfJoinCount++ : static::$selfJoinCount); } /** * Get the results of the relationship. * * @return mixed */ public function getResults() { return $this->query->get(); } /** * Set the constraints for an eager load of the relation. * * @param array $models * * @return void */ public function addEagerConstraints(array $models) { $this->query->whereNested(function (Builder $inner) use ($models) { // We will use this query in order to apply constraints to the // base query builder $outer = $this->parent->newQuery()->setQuery($inner); foreach ($models as $model) { $this->addEagerConstraint($outer, $model); } }); } /** * Match the eagerly loaded results to their parents. * * @param array $models * @param EloquentCollection $results * @param string $relation * * @return array */ public function match(array $models, EloquentCollection $results, $relation) { foreach ($models as $model) { $related = $this->matchForModel($model, $results); $model->setRelation($relation, $related); } return $models; } /** * @param Model $model * @param EloquentCollection $results * * @return Collection */ protected function matchForModel(Model $model, EloquentCollection $results) { $result = $this->related->newCollection(); foreach ($results as $related) { if ($this->matches($model, $related)) { $result->push($related); } } return $result; } /** * Get the plain foreign key. * * @return mixed */ public function getForeignKeyName() { // Return a stub value for relation // resolvers which need this function. return NestedSet::PARENT_ID; } }
Simpan