Issues (84)

app/Http/Controllers/SeriesController.php (5 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Association;
6
use App\Round;
7
use App\Schedule;
8
use App\Series;
9
use Bouncer;
0 ignored issues
show
The type Bouncer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Illuminate\Http\Request;
11
12
class SeriesController extends Controller
13
{
14
15
    public function view(Series $series) {
16
        return view('series.view', [
17
            'series' => $series,
18
        ]);
19
    }
20
21
    /**
22
     * Store a new series.
23
     *
24
     * @param  Request  $request
25
     * @return Response
0 ignored issues
show
The type App\Http\Controllers\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
26
     */
27
    public function store(Request $request) {
28
        $validatedData = $request->validate([
0 ignored issues
show
The assignment to $validatedData is dead and can be removed.
Loading history...
29
            'name' => 'required|max:255',
30
        ]);
31
32
        $series = new series;
33
34
        $series->name = $request->name;
35
        $series->user_id = $request->user_id;
36
        $series->association_id = $request->association_id;
37
38
        $series->save();
39
40
        return redirect()->route('association.series', ['association' => Association::find($request->association_id)]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...uest->association_id))) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
41
    }
42
43
    public function edit(Series $series) {
44
        return view('series.edit', [
45
            'current_user' => \Auth::user(),
46
            'series' => $series,
47
            //'start_date_string' => $series->start_date !== NULL ? date('Y-m-d', $series->start_date) : NULL,
48
            'start_date_string' => $series->start_date !== NULL ? date('Y-m-d', strtotime($series->start_date)) : NULL,
49
            //'end_date_string' => $series->end_date !== NULL ? date('Y-m-d', $series->end_date) : NULL,
50
            'end_date_string' => $series->end_date !== NULL ? date('Y-m-d', strtotime($series->end_date)) : NULL,
51
            'associations' => Association::where('user_id', \Auth::user()->id)->get(),
52
            'association_id' => $series->association_id,
53
            'schedules' => Schedule::where('series_id', $series->id)->orderBy('sequence', 'ASC')->orderBy('start_date', 'ASC')->get(),
54
        ]);
55
    }
56
57
    public function create() {
58
        return view('series.create', [
59
            'current_user' => \Auth::user(),
60
            'associations' => Association::where('user_id', \Auth::user()->id)->get(),
61
        ]);
62
    }
63
64
    public function update(Request $request) {
65
        $validatedData = $request->validate([
0 ignored issues
show
The assignment to $validatedData is dead and can be removed.
Loading history...
66
            'name' => 'required|max:255',
67
        ]);
68
69
        $series = series::find($request->id);
70
71
        $series->name = $request->name;
72
        //$series->user_id = $request->user_id;
73
74
        if (isset($request->association_id)) {
75
            $series->association_id = $request->association_id;
76
        }
77
78
        if ($request->start_date !== NULL) {
79
            //$start_date_timestamp = strtotime($request->start_date);
80
            //$series->start_date = $start_date_timestamp;
81
            $series->start_date = $request->start_date;
82
        }
83
        else {
84
            $series->start_date = NULL;
85
        }
86
87
        if ($request->end_date !== NULL) {
88
            //$end_date_timestamp = strtotime($request->end_date);
89
            //$series->end_date = $end_date_timestamp;
90
            $series->end_date = $request->end_date;
91
        }
92
        else {
93
            $series->end_date = NULL;
94
        }
95
96
        $series->save();
97
98
        $request->session()->flash('message', __('Successfully updated series :series!', ['series' => $series->name]));
99
100
        return redirect()->route('series.view', ['series' => $series]);
101
    }
102
103
    public function schedules(Series $series) {
104
        return view('series.schedules', ['series' => $series]);
105
    }
106
107
}
108