osb/app/Models/Rtm.php
Deon George 1c4cb6f38c
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 31s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
Fix usage_broadband, since our usage data is a float
2024-07-26 14:46:06 +10:00

50 lines
935 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
class Rtm extends Model
{
use HasFactory;
protected $table = 'rtm';
public $timestamps = FALSE;
/* RELATIONS */
/**
* Subordinate RTM entries
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function children()
{
return $this->hasMany(self::class,'parent_id');
}
public function owner()
{
return $this->hasOneThrough(User::class,Account::class,'id','id','account_id','user_id');
}
/* METHODS */
/**
* Return all the children RTM records that this record is parent of
*
* @return Collection
*/
public function children_all(): Collection
{
$result = collect();
$result->push($this->withoutRelations());
foreach ($this->children as $o)
$result = $result->merge($o->children_all());
return $result;
}
}