From 74e73666e5f79fe5862bc9cd2c8d244004c381b4 Mon Sep 17 00:00:00 2001 From: horus Date: Tue, 24 Mar 2020 17:18:39 +0100 Subject: Integrate chart.js to display anime stats. --- app/Http/Controllers/AnimeController.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'app/Http/Controllers/AnimeController.php') diff --git a/app/Http/Controllers/AnimeController.php b/app/Http/Controllers/AnimeController.php index d43b1f8..9bbd3e8 100644 --- a/app/Http/Controllers/AnimeController.php +++ b/app/Http/Controllers/AnimeController.php @@ -20,17 +20,34 @@ class AnimeController extends Controller { public function showAnime($mal_id) { $anime = Anime::where('mal_id', $mal_id)->get()->first(); + if ( is_null($anime) ) { + abort(404); + } $anime["stats"] = $anime->getStats()->orderBy('created_at', 'asc')->get(); foreach( $anime["stats"] as $stats ) { $score[] = $stats->score; - $scored_at[] = $stats->created_at->toDateString(); + $created_at[] = $stats->created_at->toDateString(); + $rank[] = $stats->rank; + $popularity[] = $stats->popularity; + $members[] = $stats->members; + $favorites[] = $stats->favorites; } $anime["score"] = $score; - $anime["score_label"] = $scored_at; + $anime["rank"] = $rank; + $anime["popularity"] = $popularity; + $anime["members"] = $members; + $anime["favorites"] = $favorites; + $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 = Anime::get(); + + return view('index_anime', ["all_anime" => $anime]); + } } -- cgit v1.2.3