clrghouz/app/Traits/GetNode.php

32 lines
577 B
PHP
Raw Normal View History

2019-04-27 13:57:39 +00:00
<?php
namespace App\Traits;
use App\Models\{Node,Zone};
trait GetNode
{
/**
* Get an FTN record
* If the record doesnt exist, we'll create it
*/
protected function get_node($z,$n,$f,$p=0,$create=TRUE)
{
$zo = Zone::firstOrCreate(['id'=>$z]);
$no = Node::firstOrNew(['zone_id'=>$zo->id,'host_id'=>$n,'node_id'=>$f,'point_id'=>$p]);
if (! $no->exists AND $create)
{
$no->active = FALSE;
$no->system = 'AUTO DISCOVERED';
$no->sysop = 'UNKNOWN';
$no->location = '';
$no->baud = 0;
$no->save();
}
return ($no->exists) ? $no : NULL;
}
}