belongsToMany(Attender::class, 'event_attenders', 'event_id', 'attender_id'); } /* |-------------------------------------------------------------------------- | SCOPES |-------------------------------------------------------------------------- */ /* |-------------------------------------------------------------------------- | ACCESSORS |-------------------------------------------------------------------------- */ /* |-------------------------------------------------------------------------- | MUTATORS |-------------------------------------------------------------------------- */ public function setImageAttribute($value) { $attribute_name = "image"; $disk = "public"; $destination_path = "events/images"; $this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path, $fileName = null); } public function setFileAttribute($value) { $attribute_name = "file"; $disk = "public"; $destination_path = "files/uploads"; $this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path, $fileName = null); } public static function boot() { parent::boot(); static::deleting(function($obj) { if($obj->image){ \Storage::disk('public')->delete($obj->image); } if($obj->file){ \Storage::disk('public')->delete($obj->file); } }); } }