ldc-com-app-bo/app/Models/Directories.php
Vincent BRIDIER f01e1501b4 init
2021-01-15 14:47:59 +01:00

21 lines
508 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Directories extends Model
{
public function getParentsAttribute() {
return $this->constructParents($this->parent);
}
private function constructParents($id, $parents = []) {
$tmp = Directories::find($id);
array_push($parents, $tmp);
if ($tmp->parent != NULL) {
return $this->constructParents($tmp->parent, $parents);
}
return array_reverse($parents);
}
}