*/ protected $casts = [ 'id' => 'integer', 'full_name' => 'string', 'unique_name' => 'string', 'information_url' => '?string', 'image_path' => 'string', 'image_mimetype' => 'string', 'podcast_id' => '?integer', 'episode_id' => '?integer', 'created_by' => 'integer', 'updated_by' => 'integer', ]; /** * Saves a picture in `public/media/persons/` */ public function setImage(Image $image): static { helper('media'); // Save image $image->saveImage('persons', $this->attributes['unique_name']); $this->attributes['image_mimetype'] = $image->mimetype; $this->attributes['image_path'] = $image->path; return $this; } public function getImage(): Image { return new Image(null, $this->attributes['image_path'], $this->attributes['image_mimetype'],); } /** * @return object[] */ public function getRoles(): array { if ($this->attributes['podcast_id'] === null) { throw new RuntimeException('Person must have a podcast_id before getting roles.',); } if ($this->roles === null) { $this->roles = (new PersonModel())->getPersonRoles( $this->id, $this->attributes['podcast_id'], $this->episode_id ); } return $this->roles; } }