clrghouz/app/Models/Node.php

26 lines
551 B
PHP
Raw Normal View History

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