27 lines
630 B
PHP
27 lines
630 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class Documents extends Model
|
||
|
|
{
|
||
|
|
|
||
|
|
public function getOthersLangAttribute() {
|
||
|
|
return Documents::where('parent', '=', $this->id)->get();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getParentsAttribute() {
|
||
|
|
return $this->constructParents($this->directory);
|
||
|
|
}
|
||
|
|
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
}
|