質問編集履歴
1
コードを詳細に書き直しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,6 +9,12 @@
|
|
9
9
|
|
10
10
|
■controllerファイル
|
11
11
|
```php
|
12
|
+
//追加ページ
|
13
|
+
public function create() {
|
14
|
+
$month = Client::$month;
|
15
|
+
return view('client.create', compact('month'));
|
16
|
+
}
|
17
|
+
//追加の確認
|
12
18
|
public function confirm(ClientRequest $request) {
|
13
19
|
$data = $request->all();
|
14
20
|
if (isset($request->month)) {
|
@@ -16,20 +22,77 @@
|
|
16
22
|
}
|
17
23
|
return view('client.confirm')->with($data);
|
18
24
|
}
|
25
|
+
|
26
|
+
//追加の処理
|
27
|
+
public function store(ClientRequest $request) {
|
28
|
+
$action = $request->get('action');// name=action の value名を取得
|
29
|
+
$input = $request->except('action');// 入力内容を取得
|
30
|
+
|
31
|
+
if ($action === "確定") {
|
32
|
+
$clients = new Client();
|
33
|
+
$clients->name = $request->ClientName;
|
34
|
+
$clients->month = $request->ClientMonth;
|
35
|
+
$clients->body = $request->ClientBody;
|
36
|
+
$clients->save();
|
37
|
+
return redirect('/client/list');
|
38
|
+
} else {
|
39
|
+
return redirect('/client/create')->withInput($input);
|
40
|
+
}
|
41
|
+
|
42
|
+
}
|
19
43
|
```
|
20
44
|
|
21
45
|
■viewファイル(入力画面)
|
22
46
|
```php
|
47
|
+
<form class="" action="{{ url('/client/confirm') }}" method="post">
|
48
|
+
{{ csrf_field() }}
|
49
|
+
|
50
|
+
<p>
|
51
|
+
<input type="text" name="ClientName" placeholder="名前" value="{{ old('ClientName') }}">
|
52
|
+
@if($errors->has('ClientName'))
|
53
|
+
<span class="error">{{ $errors->first('ClientName') }}</span>
|
54
|
+
@endif
|
55
|
+
</p>
|
56
|
+
|
57
|
+
<p>
|
23
58
|
@foreach($month as $key => $value)
|
24
59
|
<label class="checkbox-inline">
|
25
60
|
{!! Form::checkbox('month[]', $value) !!}
|
26
61
|
{{ $value }}
|
27
62
|
</label>
|
28
63
|
@endforeach
|
64
|
+
</p>
|
65
|
+
|
66
|
+
<p>
|
67
|
+
<textarea name="ClientBody" rows="8" cols="80" placeholder="本文">{{ old('ClientBody') }}</textarea>
|
68
|
+
@if($errors->has('ClientBody'))
|
69
|
+
<span class="error">{{ $errors->first('ClientBody') }}</span>
|
70
|
+
@endif
|
71
|
+
</p>
|
72
|
+
|
73
|
+
<input type="submit" value="登録">
|
74
|
+
</form>
|
29
75
|
```
|
30
76
|
|
31
77
|
■viewファイル(確認画面)
|
32
78
|
```php
|
79
|
+
<form class="" action="{{ url('/client') }}" method="post">
|
80
|
+
|
81
|
+
<input type="hidden" name="ClientName" value="{{ $ClientName }}">
|
82
|
+
<input type="hidden" name="ClientMonth" value="{{ $month }}">
|
83
|
+
<input type="hidden" name="ClientBody" value="{{ $ClientBody }}">
|
84
|
+
{{ csrf_field() }}
|
85
|
+
|
86
|
+
この内容で登録します。
|
87
|
+
|
88
|
+
<ul>
|
89
|
+
<li>{{ $ClientName }}</li>
|
90
|
+
<li>{{ $month }}</li>
|
91
|
+
<li>{!! nl2br(e($ClientBody)) !!}</li>
|
92
|
+
</ul>
|
93
|
+
|
33
94
|
<input type="submit" name="action" value="戻る">
|
34
95
|
<input type="submit" name="action" value="確定">
|
96
|
+
|
97
|
+
</form>
|
35
98
|
```
|