$anime * @property string $name * @property int $series_id * @property string $slug * * @method static SeriesFactory factory(...$parameters) */ #[Table(Series::TABLE, Series::ATTRIBUTE_ID)] class Series extends BaseModel implements Auditable, SoftDeletable { use HasAudits; use HasFactory; use Searchable; use SoftDeletes; use Submitable; final public const string TABLE = 'series'; final public const string ATTRIBUTE_ID = 'series_id'; final public const string ATTRIBUTE_NAME = 'name'; final public const string ATTRIBUTE_SLUG = 'slug'; final public const string RELATION_ANIME = 'anime'; final public const string RELATION_ANIME_SYNONYMS = 'anime.synonyms'; /** * The event map for the model. * * Allows for object-based events for native Eloquent events. * * @var array */ protected $dispatchesEvents = [ 'created' => SeriesCreated::class, 'deleted' => SeriesDeleted::class, 'restored' => SeriesRestored::class, 'updated' => SeriesUpdated::class, ]; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ Series::ATTRIBUTE_NAME, Series::ATTRIBUTE_SLUG, ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ Series::ATTRIBUTE_NAME => 'string', Series::ATTRIBUTE_SLUG => 'string', ]; } /** * Modify the query used to retrieve models when making all of the models searchable. */ protected function makeAllSearchableUsing(Builder $query): Builder { return $query->with(Series::RELATION_ANIME_SYNONYMS); } /** * Get the indexable data array for the model. */ public function toSearchableArray(): array { return match ($driver = Config::get('scout.driver')) { 'collection', 'elastic' => SeriesElasticModel::toSearchableArray($this), 'typesense' => SeriesTypesenseModel::toSearchableArray($this), default => throw new RuntimeException("Unsupported {$driver} search driver configured."), }; } /** * Get the route key for the model. * * @noinspection PhpMissingParentCallCommonInspection */ public function getRouteKeyName(): string { return Series::ATTRIBUTE_SLUG; } public function getName(): string { return $this->name; } public function getSubtitle(): string { return $this->slug; } /** * @return BelongsToMany */ public function anime(): BelongsToMany { return $this->belongsToMany(Anime::class, AnimeSeries::TABLE, AnimeSeries::ATTRIBUTE_SERIES, AnimeSeries::ATTRIBUTE_ANIME) ->using(AnimeSeries::class) ->as(AnimeSeriesJsonResource::$wrap) ->withPivot([AnimeSeries::ATTRIBUTE_ID]) ->withTimestamps(); } }