User optimisation and code cleanup

This commit is contained in:
2024-07-05 22:56:02 +10:00
parent b6b036e06d
commit 326b1dcfc5
12 changed files with 80 additions and 294 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
class Rtm extends Model
{
@@ -23,4 +24,20 @@ class Rtm extends Model
{
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;
}
}