clrghouz/app/Models/Node.php
2019-04-27 23:59:00 +10:00

26 lines
551 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Node extends Model
{
protected $fillable = ['zone_id','host_id','node_id','point_id'];
public function flags() {
return $this->belongsToMany(Flag::class);
}
public function getFTNAttribute()
{
return sprintf('%s:%s/%s.%s',$this->zone_id,$this->host_id,$this->node_id,$this->point_id);
}
public function hasFlag($relation, $model)
{
return (bool) $this->{$relation}()
->wherePivot($model->getForeignKey(),$model->{$model->getKeyName()})
->count();
}
}