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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Anime;
use App\AnimeStats;
use Carbon\Carbon;
class AnimeController extends Controller {
/**
* Shows the index page.
*
* @return Response
*/
public function showAnime($mal_id, $slug = "") {
$anime = Anime::where('mal_id', $mal_id)->get()->first();
if ( is_null($anime) ) {
abort(404);
}
/**
* Redirects to correct slug.
*/
if ( $slug != Str::slug($anime->title_pref) ) {
return redirect()->route('anime', ["mal_id" => $anime->mal_id, "slug" => Str::slug($anime->title_pref)]);
}
$anime["stats"] = $anime->getStats()->orderBy('created_at', 'asc')->get();
foreach( $anime["stats"] as $stats ) {
$score[] = $stats->score;
$created_at[] = $stats->created_at->toDateString();
$rank[] = $stats->rank;
$popularity[] = $stats->popularity;
$members[] = $stats->members;
$favorites[] = $stats->favorites;
$watching[] = $stats->watching;
$completed[] = $stats->completed;
$onhold[] = $stats->onhold;
$dropped[] = $stats->dropped;
$plan_to_watch[] = $stats->plan_to_watch;
$scored_by[] = $stats->scored_by;
$score_1[] = $stats->score_1;
$score_2[] = $stats->score_2;
$score_3[] = $stats->score_3;
$score_4[] = $stats->score_4;
$score_5[] = $stats->score_5;
$score_6[] = $stats->score_6;
$score_7[] = $stats->score_7;
$score_8[] = $stats->score_8;
$score_9[] = $stats->score_9;
$score_10[] = $stats->score_10;
}
$anime["score"] = $score;
$anime["rank"] = $rank;
$anime["popularity"] = $popularity;
$anime["members"] = $members;
$anime["favorites"] = $favorites;
$anime["watching"] = $watching;
$anime["onhold"] = $onhold;
$anime["plan_to_watch"] = $plan_to_watch;
$anime["completed"] = $completed;
$anime["dropped"] = $dropped;
$anime["scored_by"] = $scored_by;
$anime["score_1"] = $score_1;
$anime["score_2"] = $score_2;
$anime["score_3"] = $score_3;
$anime["score_4"] = $score_4;
$anime["score_5"] = $score_5;
$anime["score_6"] = $score_6;
$anime["score_7"] = $score_7;
$anime["score_8"] = $score_8;
$anime["score_9"] = $score_9;
$anime["score_10"] = $score_10;
$anime["chart_label"] = $created_at;
$anime["basic_data"] = DB::select('select score, rank, popularity, members, favorites from anime join stats on stats.id = ( select id from stats where anime.mal_id = stats.mal_id order by created_at desc limit 1) where anime.mal_id = ?', [$mal_id])[0];
return view('anime', [ "anime" => $anime ]);
}
public function showAllAnime() {
$anime = new Anime;
$most_surprising_anime = $anime->setTable('view_anime_index');
$most_surprising_anime = $most_surprising_anime->simplePaginate(10);
#$anime = $anime->setTable('anime');
$anime = $anime->where('airing_status', env('ANIME_IS_AIRING'));
$anime = $anime->orderBy('watching', 'desc');
$anime = $anime->orderBy('members', 'desc');
$anime = $anime->orderBy('score_today', 'desc');
$anime = $anime->simplePaginate(10);
return view('index_anime', ["all_anime" => $anime, "most_suprising_anime" => $most_surprising_anime]);
}
}
|