osb/app/Models/Rtm.php

50 lines
935 B
PHP
Raw Permalink Normal View History

2018-07-06 06:57:49 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2018-07-06 06:57:49 +00:00
use Illuminate\Database\Eloquent\Model;
2024-07-05 12:56:02 +00:00
use Illuminate\Support\Collection;
2018-07-06 06:57:49 +00:00
class Rtm extends Model
{
use HasFactory;
protected $table = 'rtm';
2018-07-06 06:57:49 +00:00
public $timestamps = FALSE;
/* RELATIONS */
/**
* Subordinate RTM entries
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function children()
{
return $this->hasMany(self::class,'parent_id');
}
2024-07-05 12:56:02 +00:00
public function owner()
{
return $this->hasOneThrough(User::class,Account::class,'id','id','account_id','user_id');
}
/* METHODS */
2024-07-05 12:56:02 +00:00
/**
* 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;
}
2018-07-06 06:57:49 +00:00
}