mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
82 lines
1.6 KiB
PHP
82 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Concerns\FilteredByLetter;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Jikan\Jikan;
|
|
use Jikan\Request\Magazine\MagazinesRequest;
|
|
|
|
/**
|
|
* Class Magazine
|
|
* @package App
|
|
*/
|
|
class Magazine extends JikanApiSearchableModel
|
|
{
|
|
use FilteredByLetter, HasFactory;
|
|
protected array $filters = ["order_by", "sort", "letter"];
|
|
|
|
/**
|
|
* 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 = 'magazines';
|
|
|
|
/**
|
|
* The attributes excluded from the model's JSON form.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'_id', 'expiresAt'
|
|
];
|
|
|
|
public function __construct(array $attributes = [])
|
|
{
|
|
parent::__construct($attributes);
|
|
$this->displayNameFieldName = "name";
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public static function scrape() : array
|
|
{
|
|
$data = app('JikanParser')->getMagazines(new MagazinesRequest());
|
|
|
|
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'
|
|
];
|
|
}
|
|
}
|