TaskController::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\CompleteTask;
6
use App\Http\Requests\DestroyTask;
7
use App\Http\Requests\ShowTask;
8
use App\Http\Requests\StoreTask;
9
use App\Http\Requests\UpdateTask;
10
use App\Task;
11
use App\User;
12
use Illuminate\Support\Facades\Redirect;
13
use Illuminate\Support\Facades\Session;
14
15
class TaskController extends Controller
16
{
17
    /**
18
     * Display a listing of the resource.
19
     *
20
     * @return \Illuminate\Http\Response
21
     */
22
    public function index()
23
    {
24
        $tasks = Task::all();
25
        $users = User::all();
26
27
        return view('tasks_php', ['tasks' => $tasks, 'users' => $users]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('tasks_php',...ks, 'users' => $users)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
28
    }
29
30
    /**
31
     * Show the form for creating a new resource.
32
     *
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function create()
36
    {
37
        $users = User::all();
38
39
        return view('create_tasks', ['users' => $users]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('create_task...ray('users' => $users)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param \Illuminate\Http\Request $request
46
     *
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function store(StoreTask $request)
50
    {
51
        Task::create([
52
            'name'             => $request->name,
53
            'description'      => $request->description,
54
            'user_id'          => $request->user_id,
55
            'completed'        => false,
56
            ]);
57
58
        Session::flash('status', 'Created ok!');
59
60
        return Redirect::to('/tasks_php/create');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...to('/tasks_php/create') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
61
    }
62
63
    /**
64
     * Display the specified resource.
65
     *
66
     * @param \App\Task $task
67
     *
68
     * @return \Illuminate\Http\Response
69
     */
70
    public function show(ShowTask $request, Task $task)
71
    {
72
        return view('show_tasks', ['task' => $task]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('show_tasks', array('task' => $task)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
73
    }
74
75
    /**
76
     * Show the form for editing the specified resource.
77
     *
78
     * @param \App\Task $task
79
     *
80
     * @return \Illuminate\Http\Response
81
     */
82
    public function edit(Task $task)
83
    {
84
        $users = User::all();
85
86
        return view('edit_tasks', ['task' => $task, 'users' => $users]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('edit_tasks'...sk, 'users' => $users)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
87
    }
88
89
    /**
90
     * Update the specified resource in storage.
91
     *
92
     * @param \Illuminate\Http\Request $request
93
     * @param \App\Task                $task
94
     *
95
     * @return \Illuminate\Http\Response
96
     */
97
    public function update(UpdateTask $request, Task $task)
98
    {
99
        $task->update($request->only(['name', 'user_id']));
100
101
        Session::flash('status', 'Edited ok!');
102
103
        return Redirect::to('/tasks_php/edit/'.$task->id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...php/edit/' . $task->id) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
104
    }
105
106
    public function complete(CompleteTask $request, Task $task)
107
    {
108
        $task->update(['completed' => $task->completed ? false : true]);
109
110
        Session::flash('status', 'Status changed!');
111
112
        return Redirect::to('/tasks_php');
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param \App\Task $task
119
     *
120
     * @return \Illuminate\Http\Response
121
     */
122
    public function destroy(DestroyTask $request, Task $task)
123
    {
124
        $task->delete();
125
        Session::flash('status', 'Task was deleted successful!');
126
127
        return Redirect::to('/tasks_php');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...irect::to('/tasks_php') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
128
    }
129
}
130