jikan-rest/app/GenreAnime.php

82 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App;
use Jenssegers\Mongodb\Eloquent\Model;
use Jikan\Request\Genre\AnimeGenresRequest;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* Class Magazine
* @package App
*/
class GenreAnime extends JikanApiSearchableModel
{
use HasFactory;
protected array $filters = [];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'mal_id', 'name', 'url', 'count',
'createdAt', 'modifiedAt'
];
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'genres_anime';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'_id', 'expiresAt'
];
/**
* @return array
*/
public static function scrape() : array
{
$data = app('JikanParser')->getAnimeGenres(new AnimeGenresRequest());
return json_decode(
app('SerializerV4')
->serialize($data, 'json'),
true
);
}
public function toSearchableArray(): array
{
return [
'id' => (string) $this->mal_id,
'mal_id' => (int) $this->mal_id,
'name' => $this->name,
'count' => $this->count
];
}
public function typesenseQueryBy(): array
{
return [
'name'
];
}
public function getTitleAttributeName(): string
{
return 'name';
}
}