slug_name); if (!File::exists($path)) { File::makeDirectory($path); } }); static::updating(function (Project $project) { $oldName = Project::where('id', $project->id)->first()->name; $oldPath = Project::ticketAssetsPath($oldName); $newPath = Project::ticketAssetsPath($project->slug_name); if (File::exists($oldPath)) { File::move($oldPath, $newPath); } else { File::makeDirectory($newPath); } }); static::deleted(function (Project $project) { $path = Project::ticketAssetsPath($project->slug_name); if (File::exists($path)) { File::deleteDirectory($path); } }); } public function tickets() { return $this->hasMany('App\Models\Ticket', 'project_id'); } public function getSlugNameAttribute() { return Str::slug($this->name); } protected static function ticketAssetsPath(string $str) { return public_path(sprintf('fichiers/%s', $str)); } }