*/ protected $casts = [ 'id' => 'integer', 'full_name' => 'string', 'unique_name' => 'string', 'information_url' => '?string', 'image_path' => 'string', 'image_mimetype' => 'string', 'created_by' => 'integer', 'updated_by' => 'integer', ]; /** * Saves a picture in `public/media/persons/` * * @param UploadedFile|File|null $image */ public function setImage($image = null): self { if ($image !== null) { helper('media'); $this->attributes['image_mimetype'] = $image->getMimeType(); $this->attributes['image_path'] = save_media( $image, 'persons', $this->attributes['unique_name'], ); $this->image = new Image( $this->attributes['image_path'], $this->attributes['image_mimetype'], ); $this->image->saveSizes(); } return $this; } public function getImage(): Image { return new Image( $this->attributes['image_path'], $this->attributes['image_mimetype'], ); } }