質問編集履歴
3
説明不足な点があり、追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,7 +12,21 @@
|
|
12
12
|
|
13
13
|
modal.blade.php
|
14
14
|
```php
|
15
|
-
<!--
|
15
|
+
<!-- 新規登録 -->
|
16
|
+
<form id="task-form" method="POST" action="{{ route('done_task') }}">
|
17
|
+
@csrf
|
18
|
+
<input type="title" id="title_edit" name="title">
|
19
|
+
<input type="date" id="start_edit" name="start">
|
20
|
+
<input type="color" id="color_edit" name="textColor">
|
21
|
+
<div class="modal-btn">
|
22
|
+
<button class="modal__btn modal__btn-primary" type="submit">登録する</button>
|
23
|
+
<a id="expire-btn" class="modal__btn" data-micromodal-close aria-label="Close this dialog window">キャンセル</a>
|
24
|
+
</div>
|
25
|
+
</form>
|
26
|
+
```
|
27
|
+
edit_modal.blade.php
|
28
|
+
```php
|
29
|
+
<!-- 更新 -->
|
16
30
|
<form id="task-form" method="POST" action="{{ route('editEvent') }}">
|
17
31
|
@csrf
|
18
32
|
<input type="hidden" id="id" value="" name="id">
|
2
説明不足な点があり、追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,8 +12,19 @@
|
|
12
12
|
|
13
13
|
modal.blade.php
|
14
14
|
```php
|
15
|
+
<!-- 入力フォーム -->
|
16
|
+
<form id="task-form" method="POST" action="{{ route('editEvent') }}">
|
17
|
+
@csrf
|
18
|
+
<input type="hidden" id="id" value="" name="id">
|
19
|
+
<input type="title" id="title_edit" name="title" value="">
|
20
|
+
<input type="date" id="start_edit" name="start" value="">
|
21
|
+
<input type="color" id="color_edit" name="textColor" value="">
|
22
|
+
<div class="modal-btn">
|
23
|
+
<button id="task-update" class="modal__btn modal__btn-primary" type="submit">変更する</button>
|
15
|
-
<!-- 削除ボタン -->
|
24
|
+
<!-- 削除ボタン -->
|
16
|
-
<a href="#" id="delete-task" class="cancel-btn">削除する</a>
|
25
|
+
<a href="#" id="delete-task" class="cancel-btn">削除する</a>
|
26
|
+
</div>
|
27
|
+
</form>
|
17
28
|
```
|
18
29
|
|
19
30
|
calendar.js
|
@@ -71,7 +82,34 @@
|
|
71
82
|
|
72
83
|
return redirect('/home');
|
73
84
|
}
|
85
|
+
|
86
|
+
public function editEventDate(Request $request)
|
87
|
+
{
|
88
|
+
$task = DoneTask::find($request->input('id'));
|
89
|
+
|
90
|
+
$task->start = $request->input('start');
|
91
|
+
|
92
|
+
$task->textColor = $request->input('textColor');
|
93
|
+
if(isset($_POST['title']))
|
94
|
+
{
|
95
|
+
$title = implode(',', $_POST['title']);
|
96
|
+
$task->title = $title;
|
97
|
+
}
|
98
|
+
|
99
|
+
$task->save();
|
100
|
+
|
101
|
+
return redirect('/home');
|
102
|
+
}
|
74
103
|
```
|
104
|
+
|
105
|
+
web.php
|
106
|
+
```php
|
107
|
+
Route::get('/home', 'DoneTaskController@index');
|
108
|
+
Route::post('/store', 'DoneTaskController@store')->name('done_task');
|
109
|
+
Route::post('/editEventDate', 'DoneTaskController@editEventDate')->name('editEvent');
|
110
|
+
Route::post('/deleteEvent', 'DoneTaskController@deleteEvent')->name('deleteEvent');
|
111
|
+
|
112
|
+
```
|
75
113
|
上記の方法だと`info.id`が取得できないので、削除できていないのだと思われますが、代替案がわからない状態です。
|
76
114
|
|
77
115
|
###補足情報
|
1
説明不足の箇所があったため、Controllerと説明文を追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,6 +7,9 @@
|
|
7
7
|
現在はカレンダーが表示されていて、登録されているイベントをクリックするとモーダル更新用の画面が出てくるようになっています。
|
8
8
|
更新用のモーダルに登録ボタンと削除ボタンを設置して、削除ボタンを押したらデータが削除されるようにしたいです。
|
9
9
|
|
10
|
+
現在、データを表示させるindexアクションが`ajax`通信の際に`id`を返すようにしているため、更新処理の際は`value`の取得にJSを使用しました。
|
11
|
+
通常だと`form`タグの`action`属性に`id`を指定し送信すると思うのですが、`id`を渡すことができていないため、どのようにすればいいのかわからない状態です。
|
12
|
+
|
10
13
|
modal.blade.php
|
11
14
|
```php
|
12
15
|
<!-- 削除ボタン -->
|
@@ -36,6 +39,39 @@
|
|
36
39
|
event.remove();
|
37
40
|
});
|
38
41
|
```
|
42
|
+
DoneTaskController.php
|
43
|
+
```php
|
44
|
+
public function index(Request $request)
|
45
|
+
{
|
46
|
+
$user_id = Auth::id();
|
47
|
+
|
48
|
+
if ($request->ajax())
|
49
|
+
{
|
50
|
+
$data = DoneTask::select('id','title', 'start', 'textColor')->where('user_id', $user_id)->get();
|
51
|
+
return response()->json($data);
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
return view('home');
|
56
|
+
}
|
57
|
+
|
58
|
+
public function store(Done $request)
|
59
|
+
{
|
60
|
+
$task = new DoneTask;
|
61
|
+
$task->user_id = Auth::id();
|
62
|
+
$task->start = $request->input('start');
|
63
|
+
$task->textColor = $request->input('textColor');
|
64
|
+
if(isset($_POST['title']))
|
65
|
+
{
|
66
|
+
$title = implode(',', $_POST['title']);
|
67
|
+
$task->title = $title;
|
68
|
+
}
|
69
|
+
|
70
|
+
$task->save();
|
71
|
+
|
72
|
+
return redirect('/home');
|
73
|
+
}
|
74
|
+
```
|
39
75
|
上記の方法だと`info.id`が取得できないので、削除できていないのだと思われますが、代替案がわからない状態です。
|
40
76
|
|
41
77
|
###補足情報
|