summaryrefslogtreecommitdiff
path: root/app/Http/Controllers/AnimeController.php
blob: d43b1f8d6d54df403c024ebf82ddc08873ed552c (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
<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
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) {

		$anime = Anime::where('mal_id', $mal_id)->get()->first();
		$anime["stats"] = $anime->getStats()->orderBy('created_at', 'asc')->get();

		foreach( $anime["stats"] as $stats ) {
			$score[] = $stats->score;
			$scored_at[] = $stats->created_at->toDateString();
		}
		$anime["score"] = $score;
		$anime["score_label"] = $scored_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 ]);
	}
}