User optimisation and code cleanup
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user