2018-07-06 06:57:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2022-04-21 04:41:26 +00:00
|
|
|
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
|
|
|
|
{
|
2022-04-21 04:41:26 +00:00
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
protected $table = 'rtm';
|
2018-07-06 06:57:49 +00:00
|
|
|
public $timestamps = FALSE;
|
2022-04-21 04:41:26 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|