Completed
Push — master ( bd53f4...908b5b )
by Eric
03:14
created

TaskController::complete()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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