/ app / Models / Folder.php
Folder.php
 1  <?php
 2  
 3  namespace App\Models;
 4  
 5  use Illuminate\Database\Eloquent\Factories\HasFactory;
 6  use Illuminate\Database\Eloquent\Model;
 7  use Kalnoy\Nestedset\NodeTrait;
 8  
 9  class Folder extends Model
10  {
11      use HasFactory, NodeTrait;
12  
13      protected $fillable = [
14          'name',
15          'dossier_id',
16          'created_by',
17          'parent_id'
18      ];
19  
20      public function documents()
21      {
22          return $this->hasMany(Document::class);
23      }
24  
25      public function dossier()
26      {
27          return $this->belongsTo(Dossier::class);
28      }
29  
30      public function isInternal()
31      {
32          if ($this->name ==  __('documents.folders.internal')) {
33              return True;
34          }
35  
36          return $this->ancestors()->where('name', __('documents.folders.internal'))->exists();
37      }
38  
39      public function path()
40      {
41          $path = $this->ancestors()->pluck('name')->push($this->name)->implode('/');
42          $sanitizedPath = str_replace('Raiz/Expedientes/', '', $path);
43          return $sanitizedPath;
44      }
45  }