belongsTo('App\Category'); } public function getDateAttribute($value) { return Carbon::parse($value)->format('d.m.Y.'); } public function setDateAttribute($value) { $this->attributes['date'] = Carbon::createFromFormat('d.m.Y.', $value); } public function getDateEndAttribute($value) { return $value ? Carbon::parse($value)->format('d.m.Y.') : null; } public function setDateEndAttribute($value) { $this->attributes['date_end'] = $value ? Carbon::createFromFormat('d.m.Y.', $value) : null; } public function scopeOrdered($query) { return $query->orderBy('date', 'asc'); } public function scopeUpcoming($query) { return $query->where('date', '>=', Carbon::now()->toDateString()); } public function getMonthAttribute() { return Date::parse($this->attributes['date'])->format('F'); } public function getYearAttribute() { return Carbon::parse($this->attributes['date'])->format('Y.'); } public function setImageAttribute($value) { $destinationPath = 'uploads/'; if($value){ if($this->image){ File::delete($this->image); File::delete($this->thumbnail); } $valueName = pathinfo($value->getClientOriginalName(), PATHINFO_FILENAME); $extension = pathinfo($value->getClientOriginalName(), PATHINFO_EXTENSION); $newFileName = md5($valueName.time()).'.'.$extension; $img = Image::make($value->getRealPath()); $img->widen(1200, function ($constraint) { $constraint->upsize(); }); $img->save($destinationPath.'images/'.$newFileName); $img->fit(600, 600); $img->save($destinationPath.'thumbnails/'.$newFileName); $this->attributes['image'] = $destinationPath.'images/'.$newFileName; $this->attributes['thumbnail'] = $destinationPath.'thumbnails/'.$newFileName; } } }