jikan-rest/app/Profile.php
2020-07-11 13:10:40 +05:00

78 lines
1.7 KiB
PHP

<?php
namespace App;
use App\Http\HttpHelper;
use Jenssegers\Mongodb\Eloquent\Model;
use Jikan\Helper\Media;
use Jikan\Helper\Parser;
use Jikan\Jikan;
use Jikan\Model\Common\YoutubeMeta;
use Jikan\Request\Anime\AnimeRequest;
use Jikan\Request\User\UserProfileRequest;
class Profile extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'mal_id', 'username', 'url', 'image_url', 'last_online', 'gender', 'birthday', 'location', 'joined', 'anime_stats', 'manga_stats', 'favorites', 'about'
];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['images'];
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'_id', 'image_url'
];
public function setImagesAttribute($value)
{
$this->attributes['images'] = $this->getImagesAttribute();
}
public function getImagesAttribute()
{
$imageUrl = $this->attributes['image_url'];
return [
'jpg' => [
'image_url' => $imageUrl,
],
'webp' => [
'image_url' => str_replace('.jpg', '.webp', $imageUrl),
]
];
}
public static function scrape(string $username)
{
$data = app('JikanParser')->getUserProfile(new UserProfileRequest($username));
return json_decode(
app('SerializerV4')
->serialize($data, 'json'),
true
);
}
}