osb/app/Models/Rtm.php
Deon George 23f57f684e
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 32s
Create Docker Image / Final Docker Image Manifest (push) Successful in 8s
User optimisation and code cleanup
2024-07-05 22:56:02 +10:00

43 lines
795 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');
}
/**
* 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;
}
}