回答編集履歴
7
コード修正
test
CHANGED
@@ -112,7 +112,7 @@
|
|
112
112
|
|
113
113
|
$this->validate($request, [
|
114
114
|
|
115
|
-
'file' => 'image|max:3000',
|
115
|
+
'file' => 'required|image|max:3000',
|
116
116
|
|
117
117
|
]);
|
118
118
|
|
6
コード修正
test
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
このコードで5.4で動くことを確認しました。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
```ここに言語を入力
|
6
|
+
|
7
|
+
route
|
8
|
+
|
9
|
+
Route::get('/', 'UploadController@index');
|
10
|
+
|
11
|
+
Route::post('/add', 'UploadController@add')->name('add');
|
12
|
+
|
13
|
+
```
|
2
14
|
|
3
15
|
|
4
16
|
|
@@ -40,7 +52,7 @@
|
|
40
52
|
|
41
53
|
|
42
54
|
|
43
|
-
<form action="" method="post" enctype="multipart/form-data">
|
55
|
+
<form action="{{route('add')}}" method="post" enctype="multipart/form-data">
|
44
56
|
|
45
57
|
{{ csrf_field() }}
|
46
58
|
|
5
コード修正
test
CHANGED
@@ -1,28 +1,120 @@
|
|
1
|
-
```ここに言語を入力
|
2
|
-
|
3
|
-
|
1
|
+
このコードで5.4で動くことを確認しました。
|
4
|
-
|
5
|
-
$this->validate($request, [
|
6
|
-
|
7
|
-
'datafile' => 'image|max:3000',
|
8
|
-
|
9
|
-
]);
|
10
2
|
|
11
3
|
|
12
4
|
|
5
|
+
```ここに言語を入力
|
6
|
+
|
7
|
+
viewファイル
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
<!DOCTYPE html>
|
12
|
+
|
13
|
+
<html>
|
14
|
+
|
15
|
+
<head>
|
16
|
+
|
17
|
+
<title>sample</title>
|
18
|
+
|
19
|
+
<meta charset="utf-8">
|
20
|
+
|
21
|
+
</head>
|
22
|
+
|
23
|
+
<body>
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
<!-- エラーメッセージ表示部分-->
|
28
|
+
|
29
|
+
@if ($errors->any())
|
30
|
+
|
31
|
+
@foreach ($errors->all() as $error)
|
32
|
+
|
33
|
+
<p>{{ $error }}</p>
|
34
|
+
|
35
|
+
@endforeach
|
36
|
+
|
37
|
+
@endif
|
38
|
+
|
39
|
+
<!-- エラーメッセージ表示部分-->
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
<form action="" method="post" enctype="multipart/form-data">
|
44
|
+
|
45
|
+
{{ csrf_field() }}
|
46
|
+
|
13
|
-
i
|
47
|
+
<input type="file" name="file">
|
48
|
+
|
49
|
+
<input type="submit">
|
50
|
+
|
51
|
+
</form>
|
52
|
+
|
53
|
+
</body>
|
54
|
+
|
55
|
+
</html>
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```ここに言語を入力
|
62
|
+
|
63
|
+
コントローラー
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
<?php
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
namespace App\Http\Controllers;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
use Illuminate\Http\Request;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
class TestController extends Controller
|
14
80
|
|
15
81
|
{
|
16
82
|
|
17
|
-
//
|
83
|
+
//view
|
18
84
|
|
19
|
-
|
85
|
+
public function index()
|
20
86
|
|
21
|
-
|
87
|
+
{
|
22
88
|
|
23
|
-
|
89
|
+
return view('index');
|
24
90
|
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
25
|
-
|
95
|
+
//postした後の処理
|
96
|
+
|
97
|
+
public function add(Request $request)
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
$this->validate($request, [
|
102
|
+
|
103
|
+
'file' => 'image|max:3000',
|
104
|
+
|
105
|
+
]);
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
if ($request->file('file')->isValid())
|
110
|
+
|
111
|
+
{
|
112
|
+
|
113
|
+
//アップロード成功時の処理
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
26
118
|
|
27
119
|
}
|
28
120
|
|
@@ -30,4 +122,10 @@
|
|
30
122
|
|
31
123
|
|
32
124
|
|
125
|
+
エラーが出た場合は元のviewファイルにリダイレクトし、エラーメッセージを表示してくれます。エラーメッセージを変えたい場合は、resources/lang/en/validation.phpを直接いじるか、追加するなりで対応できます。詳しくはここで解説してます。
|
126
|
+
|
127
|
+
[https://qiita.com/komatzz/items/422bcba9847ca3a79fe9](https://qiita.com/komatzz/items/422bcba9847ca3a79fe9)
|
128
|
+
|
129
|
+
|
130
|
+
|
33
|
-
こ
|
131
|
+
一度これに合わせてコードを書きなおしてみてください。
|
4
コード修正
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
$this->validate($request, [
|
6
6
|
|
7
|
-
'file' => 'image|max:3000',
|
7
|
+
'datafile' => 'image|max:3000',
|
8
8
|
|
9
9
|
]);
|
10
10
|
|
3
コード修正
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
if ($request->file('file')->isValid())
|
13
|
+
if ($request->file('datafile')->isValid())
|
14
14
|
|
15
15
|
{
|
16
16
|
|
2
プログラムの修正
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
if ($request->file('file')->isValid(
|
13
|
+
if ($request->file('file')->isValid())
|
14
14
|
|
15
15
|
{
|
16
16
|
|
1
追記
test
CHANGED
@@ -30,4 +30,4 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
-
こんな感じですかね。
|
33
|
+
こんな感じですかね。5.3だとこれで動きます。5.4は未検証なので動かなかったらすみません・・・
|