blob: ac5c650ed1f2e8767e24b8f6a362e89e793b0c40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php
/**
* https://stackoverflow.com/questions/26863439/in-laravel-eloquent-inserts-an-empty-record-to-table
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
use Jikan\MyAnimeList\MalClient;
class Anime extends Model {
/*
public $id;
public $mal_id;
public $url;
public $image_url;
public $title_eng;
public $title_rom;
public $title_nat;
public $title_pref;
public $type;
*/
private $animeInfo;
/**
* Eloquent ORM
*/
protected $table = 'anime';
protected $fillable = ['mal_id','url','image_url','title_eng','title_rom','title_nat','title_pref','type',];
public function __construct( $id, $parse_info = true ) {
$this->mal_id = $id;
if ( $parse_info ) {
$jikan = new Malclient;
$this->animeInfo = $jikan->getAnime(
(new \Jikan\Request\Anime\AnimeRequest( $this->mal_id ))
);
$this->url = $this->animeInfo->GetUrl();
$this->image_url = $this->animeInfo->getImageUrl();
$this->title_eng = $this->animeInfo->getTitleEnglish();
$this->title_rom = $this->animeInfo->getTitle();
$this->title_nat = $this->animeInfo->getTitleJapanese();
$this->title_pref = $this->animeInfo->getTitle();
$this->type = $this->animeInfo->getType();
}
}
/*
public function getStats() {
return $this->hasMany('App\AnimeStats');
}
*/
protected function getInfo() {
return $this->animeInfo;
}
}
|