'datetime']; protected $fillable = ['name', 'path', 'week', 'year','status', 'end_date']; public function project() { return $this->belongsTo(Project::class); } public function getFileName() { return 'Period_'.$this->end_date->copy()->subDays($this->offset).'_'.$this->end_date; } public function getFullPathName() { return storage_path('app/'.$this->project->download_path.'/'.$this->path); } public function getReportDate() { // TODO remove year and week return self::getReportDateForYearAndWeek( $this->project, $this->year, $this->week )->toDateString(); } public static function getReportDateForYearAndWeek(Project $project, $year, $week) { $date = Carbon::now()->setISODate($year, $week); $dayOfWeek = Carbon::parse($project->mail_day)->subDay(2)->dayOfWeek; if ($dayOfWeek == 6) { $reportDay = $date->startOfWeek()->subDay(); } else { $reportDay = $date->startOfWeek()->addDays($dayOfWeek); } return $reportDay; } public function deleteMe() { if (File::exists($this->getFullPathName())) { File::delete($this->getFullPathName()); } $this->delete(); } protected static function booted(): void { parent::booted(); static::updated(function (ProjectReport $projectReport) { event(new ProjectReportStatus($projectReport)); }); } }