Flarum\Event\GetModelRelationship::isRelationship PHP Méthode

isRelationship() public méthode

public isRelationship ( string $model, string $relationship ) : boolean
$model string
$relationship string
Résultat boolean
    public function isRelationship($model, $relationship)
    {
        return $this->model instanceof $model && $this->relationship === $relationship;
    }

Usage Example

 /**
  * @param GetModelRelationship $event
  * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany|null
  */
 public function getModelRelationship(GetModelRelationship $event)
 {
     if ($event->isRelationship(Post::class, 'mentionedBy')) {
         return $event->model->belongsToMany(Post::class, 'mentions_posts', 'mentions_id', 'post_id', 'mentionedBy');
     }
     if ($event->isRelationship(Post::class, 'mentionsPosts')) {
         return $event->model->belongsToMany(Post::class, 'mentions_posts', 'post_id', 'mentions_id', 'mentionsPosts');
     }
     if ($event->isRelationship(Post::class, 'mentionsUsers')) {
         return $event->model->belongsToMany(User::class, 'mentions_users', 'post_id', 'mentions_id', 'mentionsUsers');
     }
 }
All Usage Examples Of Flarum\Event\GetModelRelationship::isRelationship
GetModelRelationship