$anime * @property string $name * @property int $series_id * @property string $slug * * @method static SeriesFactory factory(...$parameters) */ class Series extends BaseModel { use Reportable; use Searchable; final public const TABLE = 'series'; final public const ATTRIBUTE_ID = 'series_id'; final public const ATTRIBUTE_NAME = 'name'; final public const ATTRIBUTE_SLUG = 'slug'; final public const RELATION_ANIME = 'anime'; final public const RELATION_ANIME_SYNONYMS = 'anime.animesynonyms'; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ Series::ATTRIBUTE_NAME, Series::ATTRIBUTE_SLUG, ]; /** * 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 table associated with the model. * * @var string */ protected $table = Series::TABLE; /** * The primary key associated with the table. * * @var string */ protected $primaryKey = Series::ATTRIBUTE_ID; /** * Modify the query used to retrieve models when making all of the models searchable. * * @param Builder $query * @return Builder */ protected function makeAllSearchableUsing(Builder $query): Builder { return $query->with(Series::RELATION_ANIME_SYNONYMS); } /** * Get the indexable data array for the model. * * @return array */ public function toSearchableArray(): array { $array = $this->toArray(); $array['anime'] = $this->anime->map( fn (Anime $anime) => $anime->toSearchableArray() )->toArray(); return $array; } /** * Get the route key for the model. * * @return string * * @noinspection PhpMissingParentCallCommonInspection */ public function getRouteKeyName(): string { return Series::ATTRIBUTE_SLUG; } /** * Get name. * * @return string */ public function getName(): string { return $this->name; } /** * Get subtitle. * * @return string */ public function getSubtitle(): string { return $this->slug; } /** * Get the anime included in the series. * * @return BelongsToMany */ public function anime(): BelongsToMany { return $this->belongsToMany(Anime::class, AnimeSeries::TABLE, Series::ATTRIBUTE_ID, Anime::ATTRIBUTE_ID) ->using(AnimeSeries::class) ->as(AnimeSeriesResource::$wrap) ->withTimestamps(); } }