ldc-com-app-bo/app/Models/Document.php

35 lines
757 B
PHP
Raw Normal View History

2021-01-15 14:47:59 +01:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
2022-05-11 12:36:27 +02:00
class Document extends Model
2021-01-15 14:47:59 +01:00
{
2022-05-11 12:36:27 +02:00
public function getOthersLangAttribute()
{
return Document::where('parent', '=', $this->id)->get();
2021-01-15 14:47:59 +01:00
}
2022-05-11 12:36:27 +02:00
public function getParentsAttribute()
{
2021-01-15 14:47:59 +01:00
return $this->constructParents($this->directory);
}
2022-05-11 12:36:27 +02:00
private function constructParents($id, $parents = [])
{
2021-01-15 14:47:59 +01:00
$tmp = Directories::find($id);
array_push($parents, $tmp);
if ($tmp->parent != NULL) {
return $this->constructParents($tmp->parent, $parents);
}
return array_reverse($parents);
}
public function directory()
{
return $this->belongsTo(Directories::class, 'id', 'directory');
}
2021-01-15 14:47:59 +01:00
}