blob: 76a870d8aa8b555b8fa32f7349cff7f3337a50e3 (
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
|
<?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;
}
$anime["score"] = $score;
$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::simplePaginate();
return view('index_anime', ["all_anime" => $anime]);
}
}
|