Get the notifications Relationship.

@return \Illuminate\Database\Eloquent\Relations\HasMany|\Illuminate\Database\Eloquent\Relations\MorphMany
161279
public function notifynderNotifications()
    {
        $model = app('notifynder.resolver.model')->getModel(Notification::class);
        if (notifynder_config()->isPolymorphic()) {
            return $this->morphMany($model, 'to');
        }

        return $this->hasMany($model, 'to_id');
    }
1015123
public function getOwners()
    {
        return collect($this->belongsToRelations())
            ->reject(function ($relation) {
                // Rejects the relations whose foreign keys have been passed as custom attributes.
                return array_key_exists($relation->{$this->getBelongsToForeignKeyNameMethod()}(), $this->customAttributes)
                    || array_key_exists($relation->{$this->getBelongsToForeignKeyNameMethod()}(), $this->getFactoryAttributes($this->model))

                    // And the relations of the model to itself to prevent infinite recursion.
                    || $relation->getRelated() instanceof $this->model

                    // And dynamic relations in which the foreign key is selected with a subquery.
                    || !isset($this->columns[$relation->getRelated()->getForeignKey()]);
            })
            ->map(function ($relation) {
                return get_class($relation->getRelated());
            })
            ->all();
    }
757067
private function hasMany()
    {
        // Return if there are no relationships of that type
        if (!isset($this->relationships['hasMany']) || empty($this->relationships['hasMany'])) {
            return $this;
        }

        // Get current records IDs
        $ids = array_column($this->records, 'id');

        // Return if no records where found
        if (empty($ids)) {
            return $this;
        }

        // Make a associative array from current records
        $records = array_combine($ids, $this->records);

        // Iterate relationships
        foreach ($this->relationships['hasMany'] as $join) {

            // Get relationship results trought the model
            if (isset($join['model'])) {
                if (isset($this->models) && isset($this->models[$join['model']])) {
                    $instance = $this->models[$join['model']];
                } else {
                    $instance = new $join['model'];
                }
                $childs = $instance->whereIn($join['foreignKey'], $ids)->limit($join['limit'])->orderBy($join['orderBy'])->get();
            }

            // Or get relationship results by database
            if (!isset($join['model'])) {
                $join['orderBy'] = isset($join['orderBy'])? $join['orderBy'] : 'id';
                $childs = $this->db()->table($join['table'])->select(array_merge([$join['foreignKey']], $join['columns']))->whereIn($join['foreignKey'], $ids)->limit($join['limit'])->orderBy($join['orderBy'])->get();
            }

            // Group them by foreign key
            if ($childs) {
                foreach ($childs as $child) {
                    $key = $join['foreignKey'];
                    $id = $child[$key];

                    // If the ID was not required as a column to show, leave it out
                    if (!in_array($key, $join['columns'])) {
                        unset($child[$key]);
                    }

                    // Save the result
                    $join['results'][$id][] = $child;
                }
            }

            // Add relationship results to the main collection
            foreach ($records as $key => $value) {
                $id = $value[$join['localKey']];
                $records[$id][$join['alias']] = (isset($join['results'][$id]))? $join['results'][$value[$join['localKey']]] : [];
            }
        }

        // Save the records with the resolved relationships
        $this->records = array_values($records);

        // Return model instance
        return $this;
    }
140187
public function query()
    {
        $read = NotificationsStackRead::select(['stack_id'])
                ->withTrashed()
                ->where('user_id', user()->id)
                ->whereNotNull('deleted_at')
                ->pluck('stack_id');
        return $this->makeModel()->newQuery()
                        ->distinct()
                        ->select(['tbl_notifications_stack.*'])
                        ->whereHas('content', function($query) {
                            $query->where([
                                'lang_id' => lang_id()
                            ]);
                        })
                        ->whereHas('notification', function($query) {
                            $query->whereHas('type', function($subquery) {
                                $subquery->where('name', area());
                            });
                        })
                        ->where(function ($query) {
                            $query
                            ->whereNull('author_id')
                            ->orWhere('author_id', user()->id)
                            ->orWhereHas('author', function($subquery) {
                                $subquery->whereHas('roles', function($rolesQuery) {
                                    $rolesQuery->whereIn('tbl_roles.id', user()->roles->first()->getChilds());
                                });
                            })
                            ->orWhereHas('params', function($subquery) {
                                $subquery->where('model_id', user()->id);
                            });
                        })
                        ->whereNotIn('id', $read)
                        ->with('author')
                        ->with('content')->with('notification.severity')
                        ->orderBy('tbl_notifications_stack.created_at', 'desc');
    }
1264192
public function getRelations()
    {
        $relations = $columns = [];

        foreach ($this->builder->fields() as $field) {
            $columns[] = $field->column();
        }

        foreach (array_flatten($columns) as $column) {
            if (str_contains($column, '.')) {
                list($relation) = explode('.', $column);

                if (method_exists($this->model, $relation) &&
                    $this->model->$relation() instanceof Relation
                ) {
                    $relations[] = $relation;
                }
            } elseif (method_exists($this->model, $column) &&
                !method_exists(Model::class, $column)
            ) {
                $relations[] = $column;
            }
        }

        return array_unique($relations);
    }
168872
public function getChildren()
    {
        $children = [];
        $notifications = $this->caldavBackend->getNotificationsForPrincipal($this->principalUri);

        foreach ($notifications as $notification) {
            $children[] = new Node(
                $this->caldavBackend,
                $this->principalUri,
                $notification
            );
        }

        return $children;
    }
265316
public function relations()
    {
        $audit = Yii::app()->getModule('audit');
        if (!empty($audit->modelMap[get_class($this)]['relations']))
            return $audit->modelMap[get_class($this)]['relations'];
        return parent::relations();
    }
464397
public function getRelations()
    {
        if ($this->def->getTarget() === null) {
            return [];
        }

        $relations = [];
        foreach ($this->def->getTarget()->getRelations() as $relation) {
            $relations[$relation->getLocalProperty()] = $relation;
        }

        return $relations;
    }
1152889
public function getSocialAccounts()
    {
        $connected = [];
        /** @var UserSocialAccount[] $accounts */
        $accounts = $this->hasMany(UserSocialAccount::class, ['user_id' => 'id'])->all();
        /**
         * @var UserSocialAccount $account
         */
        foreach ($accounts as $account) {
            $connected[$account->provider] = $account;
        }

        return $connected;
    }
1230443
public function getForeignRelation()
    {
        $params = [
            $this->getReferencesModel(),
            $this->column,
            $this->on,
        ];

        $prefix = $this->isSelfReference() ? 'parent_' : '';

        $relation = new ForeignRelationship(
            'belongsTo',
            $params,
            $this->getForeignModelName($prefix)
        );

        return $relation;
    }
883292
public function loadRelations() {
        foreach ([
            Relation::MANY_TO_ONE => $this->belongsTo,
            Relation::MANY_TO_MANY => $this->belongsToMany,
            Relation::ONE_TO_ONE => $this->hasOne,
            Relation::ONE_TO_MANY => $this->hasMany
        ] as $type => $relations) {
            foreach ($relations as $alias => $relation) {
                if (is_string($relation)) {
                    $relation = ['model' => $relation];
                }

                $relation = $relation + [
                    'model' => null,
                    'foreignKey' => null,
                    'relatedForeignKey' => null,
                    'conditions' => null,
                    'junction' => null
                ];

                switch ($type) {
                    case Relation::MANY_TO_ONE:
                        $this->belongsTo($alias, $relation['model'], $relation['foreignKey'], $relation['conditions']);
                    break;
                    case Relation::MANY_TO_MANY:
                        $this->belongsToMany($alias, $relation['model'], $relation['junction'], $relation['foreignKey'], $relation['relatedForeignKey'], $relation['conditions']);
                    break;
                    case Relation::ONE_TO_ONE:
                        $this->hasOne($alias, $relation['model'], $relation['relatedForeignKey'], $relation['conditions']);
                    break;
                    case Relation::ONE_TO_MANY:
                        $this->hasMany($alias, $relation['model'], $relation['relatedForeignKey'], $relation['conditions']);
                    break;
                }
            }
        }

        return $this;
    }
1126817
public function getRelation()
    {
        if (!$this->relatedTableName) {
            return null;
        }
        foreach ($this->getTable()->getRelations() as $name => $relation) {
            if ($relation->getType() == RelationMap::MANY_TO_ONE) {
                if ($relation->getForeignTable()->getName() == $this->getRelatedTableName() && array_key_exists($this->getFullyQualifiedName(), $relation->getColumnMappings())) {
                    return $relation;
                }
            }
        }
    }
56810
public function getMutuals()
    {
        if (!isset($this->__mutuals)) {
            $ids = array_intersect($this->leaderIds->toArray(), $this->followerIds->toArray());
            $query = $this->getService('repos:people.person')->getQuery()->where('id', 'IN', $ids);

            $this->__mutuals = $query->toEntitySet();
        }

        return $this->__mutuals;
    }
610170
public function getNotificationDetails()
    {
        $resource = $this->getResource();
        $notificationDetails = array_merge($this->details, array());
        $notificationDetails['resource'] = array(
            'id' => $resource->getId(),
            'name' => $resource->getName(),
            'type' => $resource->getResourceType()->getName(),
        );

        return $notificationDetails;
    }
114731
public function reloadModelsWithRelationCount(): self
    {
        /** @var \Illuminate\Database\Eloquent\Builder $query */
        $query = $this->models()
            ->first()
            ->newQuery()
            ->withCount($this->relations);

        $ids = $this->getModelIds();

        $reloadedModels = $query
            ->whereKey($ids)
            ->get()
            ->filter(function (Model $model) use ($ids) {
                return in_array(
                    $model->getKey(),
                    $ids,
                    true
                );
            });

        return $this->setModels($reloadedModels);
    }
1224114
protected function guessRelation()
    {
        if ($this->relation) {
            return $this->relation;
        }

        return Str::camel(str_replace('_id', '', $this->name));
    }
1038422
public function getNotificationDetails()
    {
        $receiver = $this->getReceiver();

        $notificationDetails = array(
            'portfolio' => array(
                'id' => $this->portfolio->getId(),
                'title' => $this->portfolio->getTitle(),
                'slug' => $this->portfolio->getSlug(),
            ),
            'viewer' => array(
                'id' => $receiver->getId(),
                'publicUrl' => $receiver->getPublicUrl(),
                'lastName' => $receiver->getLastName(),
                'firstName' => $receiver->getFirstName(),
            ),
        );

        return $notificationDetails;
    }