# TaskController
app / Http / Controllers / TaskController.php
# store
public function store(StoreTaskRequest $request)
{
$task = new Task();
$task->project_id = $request->project_id;
$task->title = $request->title;
$task->description = $request->description;
$task->start_date = $request->start_time;
$task->deadLine = $request->deadLine;
$task->priority = $request->priority;
$task->status = $request->status;
$task->save();
$task->taskMemberInfo()->sync($request->members);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# taskData
public function taskDatas(Request $request){
$project = Project::with('taskInfo')
->where('id', $request->project_id)
->firstOrfail();
return view('Components.task', ['project'=>$project])
->render();
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# update
public function update(UpdateTaskRequest $request, $id)
{
$task = Task::findOrFail($id);
$task->title = $request->title;
$task->description = $request->description;
$task->start_date = $request->start_time;
$task->deadLine = $request->deadLine;
$task->priority = $request->priority;
$task->update();
$task->taskMemberInfo()->sync($request->members);
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# destroy
public function destroy($id)
{
$task = Task::findOrFail($id);
$task->delete();
}
1
2
3
4
5
2
3
4
5
# sortableComponent
public function sortableComponent(Request $request){
$project = Project::with('taskInfo')
->where('id', $request->project_id)
->firstOrFail();
if ($request->pendingStorage){
$pendingDatas = explode(',', $request->pendingStorage);
foreach ($pendingDatas as $key=>$task_id) {
$task = collect($project->taskInfo)
->where('id', $task_id)
->firstOrFail();
if ($task){
$task->sort_number = $key;
$task->status = 'pending';
$task->update();
}
}
}
if ($request->inProgressStorage){
$inProgressDatas = explode(',', $request->inProgressStorage);
foreach ($inProgressDatas as $key=>$task_id) {
$task = collect($project->taskInfo)
->where('id', $task_id)
->firstOrFail();
if ($task){
$task->sort_number = $key;
$task->status = 'in_progress';
$task->update();
}
}
}
if ($request->completeStorage){
$completeDatas = explode(',', $request->completeStorage);
foreach ($completeDatas as $key=>$task_id) {
$task = collect($project->taskInfo)
->where('id', $task_id)
->firstOrFail();
if ($task){
$task->sort_number = $key;
$task->status = 'complete';
$task->update();
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Code Overview
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreTaskRequest;
use App\Http\Requests\UpdateTaskRequest;
use App\Models\Project;
use App\Models\Task;
use Illuminate\Http\Request;
class TaskController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\StoreTaskRequest $request
* @return \Illuminate\Http\Response
*/
public function store(StoreTaskRequest $request)
{
$task = new Task();
$task->project_id = $request->project_id;
$task->title = $request->title;
$task->description = $request->description;
$task->start_date = $request->start_time;
$task->deadLine = $request->deadLine;
$task->priority = $request->priority;
$task->status = $request->status;
$task->save();
$task->taskMemberInfo()->sync($request->members);
}
public function taskDatas(Request $request){
$project = Project::with('taskInfo')
->where('id', $request->project_id)
->firstOrfail();
return view('Components.task', ['project'=>$project])
->render();
}
/**
* Display the specified resource.
*
* @param \App\Models\Task $task
* @return \Illuminate\Http\Response
*/
public function show(Task $task)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Task $task
* @return \Illuminate\Http\Response
*/
public function edit(Task $task)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\UpdateTaskRequest $request
* @param \App\Models\Task $task
* @return \Illuminate\Http\Response
*/
public function update(UpdateTaskRequest $request, $id)
{
$task = Task::findOrFail($id);
$task->title = $request->title;
$task->description = $request->description;
$task->start_date = $request->start_time;
$task->deadLine = $request->deadLine;
$task->priority = $request->priority;
$task->update();
$task->taskMemberInfo()->sync($request->members);
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Task $task
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$task = Task::findOrFail($id);
$task->delete();
}
public function sortableComponent(Request $request){
$project = Project::with('taskInfo')
->where('id', $request->project_id)
->firstOrFail();
if ($request->pendingStorage){
$pendingDatas = explode(',', $request->pendingStorage);
foreach ($pendingDatas as $key=>$task_id) {
$task = collect($project->taskInfo)
->where('id', $task_id)
->firstOrFail();
if ($task){
$task->sort_number = $key;
$task->status = 'pending';
$task->update();
}
}
}
if ($request->inProgressStorage){
$inProgressDatas = explode(',', $request->inProgressStorage);
foreach ($inProgressDatas as $key=>$task_id) {
$task = collect($project->taskInfo)
->where('id', $task_id)
->firstOrFail();
if ($task){
$task->sort_number = $key;
$task->status = 'in_progress';
$task->update();
}
}
}
if ($request->completeStorage){
$completeDatas = explode(',', $request->completeStorage);
foreach ($completeDatas as $key=>$task_id) {
$task = collect($project->taskInfo)
->where('id', $task_id)
->firstOrFail();
if ($task){
$task->sort_number = $key;
$task->status = 'complete';
$task->update();
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164