belongsToMany(Flag::class); } public function hasFlag($relation, $model) { return (bool) $this->{$relation}() ->wherePivot($model->getForeignKey(),$model->{$model->getKeyName()}) ->count(); } }