CDCController::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Http\Controllers;
9
10
use Carbon\Carbon;
11
use App\Models\Game;
12
use Illuminate\Http\Request;
13
use App\Models\GamesCoupdecoeur;
14
15
class CDCController extends Controller
16
{
17
    /**
18
     * Display a listing of the resource.
19
     *
20
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
21
     */
22
    public function index()
23
    {
24
        $cdc = GamesCoupdecoeur::all();
25
26
        return view('cdc.index', [
27
            'cdcs' => $cdc,
28
        ]);
29
    }
30
31
    /**
32
     * Show the form for creating a new resource.
33
     *
34
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
35
     */
36
    public function create()
37
    {
38
        return view('cdc.create');
39
    }
40
41
    /**
42
     * Store a newly created resource in storage.
43
     *
44
     * @param \Illuminate\Http\Request $request
45
     *
46
     * @return \Illuminate\Http\RedirectResponse
47
     */
48
    public function store(Request $request)
49
    {
50
        $this->validate($request, [
51
            'gamename' => 'required',
52
        ]);
53
54
        // Prüfen ob das Spiel auch wirklich existiert
55
        $title = explode(' -=- ', $request->get('gamename'));
56
57
        if (count($title) == 1) {
58
            $game = Game::whereTitle($title[0])
59
                ->first();
60
        } else {
61
            $game = Game::whereTitle($title[0])
62
                ->orWhere('subtitle', '=', $title[1])
63
                ->first();
64
        }
65
66
        \DB::table('games_coupdecoeur')->insert([
67
            'game_id'    => $game->id,
68
            'user_id'    => \Auth::id(),
69
            'created_at' => Carbon::now(),
70
        ]);
71
72
        return redirect()->action('MsgBoxController@cdc_add', [$game->id]);
73
    }
74
}
75