Appearance
RelationHelper
The RelationHelper
is a helper that allows you to select a list of models coming from a specific relationship on a specific entity.
fromRelation
The RelationHelper
class provides a static method fromRelation
that takes a model instance, a model id and a relation name. It will return a list of models that are related to the given model via the provided relation.
php
<?php
$models = RelationHelper::fromRelation(User::class, 1, 'posts');
The code above will return a list of posts that are related to the user with the id 1
via the posts
relation.
notFromRelation
The RelationHelper
class also provides a static method notFromRelation
that takes a model instance, a model id and a relation name. It will return a list of models that are not related to the given model via the provided relation.
php
<?php
$models = RelationHelper::notFromRelation(User::class, 1, 'posts');
The code above will return a list of posts that are not related to the user with the id 1
via the posts
relation.
Review
The RelationHelper
class is a powerful tool that allows you to easily fetch related models from a specific entity.
It's used in RelationAddDialog to fetch related model entities that are not yet attached to the current entity.