質問編集履歴

2

一部修正

2022/11/16 23:37

投稿

yc-www10
yc-www10

スコア17

test CHANGED
File without changes
test CHANGED
@@ -31,7 +31,7 @@
31
31
  public function store(Request $request){
32
32
  if($request->file('image1')!=null){
33
33
  $file_name = $request->file('image1')->getClientOriginalName();
34
- $image1 = $request->date.$file_name;
34
+ $image1 = $file_name;
35
35
  $request->file('image1')->storeAs('public/images' , $image1);
36
36
  }else{
37
37
  $image1 = null;

1

コードの追加

2022/11/16 23:34

投稿

yc-www10
yc-www10

スコア17

test CHANGED
File without changes
test CHANGED
@@ -14,5 +14,61 @@
14
14
  初めてlaravelを本番環境に上げたので、どうしたらいいかわかりません。
15
15
  ご教示よろしくお願いいたします。
16
16
 
17
+ ```form
18
+ <form method="post" action="{{ route('admin.product.store')}}" enctype="multipart/form-data" autocomplete="off">
19
+ {{csrf_field()}}
20
+ <ul class="input_wrapper">
21
+ <li class="image">
22
+ <input type="file" name="image1" id="img1" value="{{old('image1'')}}">
23
+ </li>
24
+ </ul>
25
+ </form>
26
+
27
+ ```
28
+ ```controller
29
+ use App\Models\Product;
30
+
31
+ public function store(Request $request){
32
+ if($request->file('image1')!=null){
33
+ $file_name = $request->file('image1')->getClientOriginalName();
34
+ $image1 = $request->date.$file_name;
35
+ $request->file('image1')->storeAs('public/images' , $image1);
36
+ }else{
37
+ $image1 = null;
38
+ }
39
+ Product::create([
40
+ 'image1' => $image1,
41
+ ]);
42
+ return redirect('/admin/product')->with('products', Product::get())->with('message','追加しました');
43
+
44
+ ```
45
+
46
+ ```view
47
+ <img src="{{ asset('storage/images/'.$product->image1) }}">
48
+ ```
49
+
50
+ ```htaccess
51
+ プロジェクトディレクトリ直下に置いています。
52
+ <IfModule mod_rewrite.c>
53
+ <IfModule mod_negotiation.c>
54
+ Options -MultiViews
55
+ </IfModule>
56
+
57
+ RewriteEngine On
58
+
59
+ RewriteCond %{REQUEST_FILENAME} -d [OR]
60
+ RewriteCond %{REQUEST_FILENAME} -f
61
+ RewriteRule ^ ^$1 [N]
62
+
63
+ RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
64
+ RewriteRule ^(.*)$ public/$1
65
+
66
+ RewriteCond %{REQUEST_FILENAME} !-d
67
+ RewriteCond %{REQUEST_FILENAME} !-f
68
+ RewriteRule ^ server.php
69
+
70
+ </IfModule>
71
+ ```
17
72
 
18
73
 
74
+