Passed
Push — develop ( d2ded6...15ac65 )
by Nikita
19:39
created

GamesController::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Gameap\Http\Controllers\Admin;
4
5
use Gameap\Http\Controllers\AuthController;
6
use Gameap\Models\Game;
7
use Gameap\Repositories\GameRepository;
8
use Gameap\Http\Requests\Admin\GameRequest;
9
10
class GamesController extends AuthController
11
{
12
    /**
13
     * The GameRepository instance.
14
     *
15
     * @var \Gameap\Repositories\GameRepository
16
     */
17
    protected $repository;
18
19
    /**
20
     * Create a new GameController instance.
21
     *
22
     * @param  \Gameap\Repositories\GameRepository $repository
23
     */
24 27
    public function __construct(GameRepository $repository)
25
    {
26 27
        $this->repository = $repository;
27
28 27
        parent::__construct();
29 27
    }
30
31
    /**
32
     * Display a listing of the games.
33
     *
34
     * @return \Illuminate\View\View
35
     */
36 3
    public function index()
37
    {
38 3
        return view('admin.games.list',[
39 3
            'games' => $this->repository->allWith('mods')
40
        ]);
41
    }
42
43
    /**
44
     * Display new create game page
45
     *
46
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
47
     */
48 3
    public function create()
49
    {
50 3
        return view('admin.games.create');
51
    }
52
53
    /**
54
     * Store a newly created game in storage.
55
     *
56
     * @param  \Gameap\Http\Requests\Admin\GameRequest  $request
57
     * @return \Illuminate\Http\RedirectResponse
58
     */
59 3
    public function store(GameRequest $request)
60
    {
61 3
        Game::create($request->all());
62
63 3
        return redirect()->route('admin.games.index')
64 3
            ->with('success', __('games.create_success_msg'));
65
    }
66
67
    /**
68
     * Display the specified resource.
69
     *
70
     * @param  \Gameap\Models\Game  $game
71
     * @return \Illuminate\View\View
72
     */
73 3
    public function show(Game $game)
74
    {
75 3
        return view('admin.games.view', compact('game'));
76
    }
77
78
    /**
79
     * Show the form for editing the specified resource.
80
     *
81
     * @param  \Gameap\Models\Game  $game
82
     * @return \Illuminate\View\View
83
     */
84 3
    public function edit(Game $game)
85
    {
86 3
        return view('admin.games.edit', compact('game'));
87
    }
88
89
    /**
90
     * Update the specified resource in storage.
91
     *
92
     * @param  \Gameap\Http\Requests\Admin\GameRequest  $request
93
     * @param  \Gameap\Models\Game  $game
94
     * @return \Illuminate\Http\RedirectResponse
95
     */
96 3
    public function update(GameRequest $request, Game $game)
97
    {
98 3
        $game->update($request->all());
99
100 3
        return redirect()->route('admin.games.index')
101 3
            ->with('success', __('games.update_success_msg'));
102
    }
103
104
    /**
105
     * Upgrade games and game mods from GameAP Repository
106
     *
107
     * @return \Illuminate\Http\RedirectResponse
108
     */
109 6
    public function upgrade()
110
    {
111 6
        $result = $this->repository->upgradeFromRepo();
112
113 6
        if ($result) {
114 3
            return redirect()->route('admin.games.index')
115 3
                ->with('success', __('games.upgrade_success_msg'));
116
        } else {
117 3
            return redirect()->route('admin.games.index')
118 3
                ->with('error', __('games.upgrade_fail_msg'));
119
        }
120
    }
121
122
    /**
123
     * Remove the specified resource from storage.
124
     *
125
     * @param  \Gameap\Models\Game  $game
126
     * @return \Illuminate\Http\RedirectResponse
127
     */
128 3
    public function destroy(Game $game)
129
    {
130 3
        $game->delete();
131 3
        return redirect()->route('admin.games.index')
132 3
            ->with('success', __('games.delete_success_msg'));
133
    }
134
}
135