teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

タイトル修正

2021/07/25 08:15

投稿

Sento__aa
Sento__aa

スコア21

title CHANGED
@@ -1,1 +1,1 @@
1
- シンボリックリンクを設定したい
1
+ 画像表示させるためのシンボリックリンクを設定したい
body CHANGED
File without changes

2

文章修正

2021/07/25 08:15

投稿

Sento__aa
Sento__aa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -11,8 +11,7 @@
11
11
  ■__成功イメージ__
12
12
  ![イメージ説明](186d6a9164c35dc2409afa6534e9a19a.png)
13
13
  →上記のようにstorage直下にリンクしたディレクトリ、フォルダが紐づく(?)
14
- ※参考記事 [
15
- ](https://qiita.com/10mi8o/items/ce9c875e736c7b1d2498)
14
+ ※[参考記事](http://qiita.com/10mi8o/items/ce9c875e736c7b1d2498)
16
15
 
17
16
 
18
17
  ##ためしたこと

1

質問内容の変更

2021/07/25 04:28

投稿

Sento__aa
Sento__aa

スコア21

title CHANGED
@@ -1,1 +1,1 @@
1
- シンボリックリンクを実行画像を表示させたい(Laravel)
1
+ シンボリックリンクを設定したい
body CHANGED
@@ -1,167 +1,27 @@
1
- ##やりたいこと →フォルダに保存された画像を表示したい
2
- フォームから画像を登録し、指定フォルダに保存されていることを確認できますがViewで表示できずにいます。画像を保存しているディレクトリと公開ディレクトリを紐付けるための、シンボリックリンクを実行(php artisan storage:link)ましたがパス合っていないためか表示されません。シンボリックリンクすべき場所や方法などについて解決できずにいるので何ご教示をお願いできればと思います。
3
-
4
- ????__現状ビュー画像__
5
- ![イメージ説明](66e10aa80abd808e0e801616137c756e.png)
6
-
7
- ????__画像ファイル構成__
8
- ![イメージ説明](f669d0653fe5d605baa62eef0ddf2b68.png)
9
-
10
- ????__DB(PHP My Adimin)__
11
- ![イメージ説明](20545763999350fe6024ab80509251b3.png)
12
-
13
- 各ファイルや構成は以下の通りです。
1
+ ##やりたいこと
2
+ 画像を保存しているディレクトリと公開ディレクトリを紐付けるための、シンボリックリンクを実行し、エディタ上でマークが表示されましたが上手くているのか確認したものです。
3
+ 参考記事などを確認すると、作成された「storage」をクリックすると、リンクされたディレクトリが表示されるのですが、現状「'storage'開くことが出来ません」と出るため上手くいっていないと思っているので、紐づけるためのアドバイスをいただければと思います。
14
4
  ✳️Laravel バージョン 6.20.8
15
5
  ✳️docker環境にて構築
16
6
 
17
- ■__ためしたこと__
18
- ①dockerコンテナ内でシンボリックコマンド
19
- ```ここに言語を入力
20
- root@07bb3385a7ef:/var/www/html/laravel-app# php artisan storage:link
21
- The [public/storage] directory has been linked.
22
- ```
23
- →ディレクトリがリンクされたとありますが、VSC上でもシンボリックリンクの表記(矢印)が出ておらず、どこがリンクされているのかが分からない。
24
7
 
8
+ ■__ファイル構成__
9
+ ![イメージ説明](2402fc56125ba17646cc7c24036a6d2a.png)
25
10
 
11
+ ■__成功イメージ__
12
+ ![イメージ説明](186d6a9164c35dc2409afa6534e9a19a.png)
13
+ →上記のようにstorage直下にリンクしたディレクトリ、フォルダが紐づく(?)
14
+ ※参考記事 [
15
+ ](https://qiita.com/10mi8o/items/ce9c875e736c7b1d2498)
26
16
 
27
17
 
28
- ## ■index.php(ビュー)
29
- ```@extends('layouts.app')
30
-
31
- @section('content')
32
- <table class="table table-hover">
33
- <thead class="thead-dark">
34
- <tr>
18
+ ##ためしたこと
35
- <th scope="col">社員番号</th>
36
- <th></th>
19
+ ①dockerコンテナ内でシンボリックリンク生成
37
- <th scope="col">名前</th>
20
+ ```ここに言語を入力
38
- <th scope="col">所属事業所</th>
39
- <th scope="col" colspan="4" class="d-none d-sm-table-cell">貸与品</th>
21
+ root@07bb3385a7ef:/var/www/html/laravel-app# ln -s /storage/app/public /public
40
- <th></th>
41
- </tr>
42
- </thead>
43
-
44
- <tbody>
45
- @foreach($employees as $employee)
46
- <tr>
47
- <td class="align-middle" scope="row">{{ $employee->employee_id }}</td>
48
- <td><img src="{{ asset('storage/employee_image/' . $employee->employee_image) }}" alt="画像" class="rounded-circle" width="50" height="50"></td>
49
- <td class="align-middle" scope="row">{{ $employee->employee_name }}</td>
50
- <td class="align-middle" scope="row">{{ $employee->office }}</td>
51
- <td class="d-none d-sm-table-cell">
52
- @foreach($employee->goods as $goods)
53
- <p class="vertical-middle">制服:{{ $goods->uniform }}|防寒着:{{ $goods->winter_clothes }}|靴:{{ $goods->shoes }}|その他:{{ $goods->other }}</p>
54
- @endforeach
55
- </td>
56
- <td class="align-middle" scope="row"><a href="{{ route('employee_create.show',$employee->id) }}" class="btn btn-primary">詳細</a></td>
57
- </tr>
58
- @endforeach
59
- </tbody>
60
- </table>
61
- @endsection
62
22
  ```
63
-
64
- ##■EmployeesController.php(コントローラー)
23
+ ②ファイルの属性を確認
65
- ```<?php
24
+ ```ここに言語を入力
66
-
67
- namespace App\Http\Controllers;
68
-
69
- use Illuminate\Http\Request;
70
- use App\Employee;
71
- use App\Goods;
72
-
73
- class EmployeesController extends Controller
74
-
75
- {
76
- public function index()
77
- {
78
- $employees = Employee::with('goods')->get();
79
- return view('index', ['employees' => $employees,
25
+ root@07bb3385a7ef:/var/www/html/laravel-app# ls -l public
80
- ]);
81
- }
82
-
83
- public function create()
84
- {
85
- $user =\Auth::user();
86
- return view('employee_create');
87
- }
88
-
89
- public function store(Request $request)
90
- {
91
- $request->validate([
92
- 'employee_image' => 'required',
93
- 'employee_id' => 'required',
94
- 'employee_name' => 'required',
95
- 'office' => 'required',
96
- 'uniform' => 'required',
97
- 'winter_clothes' => 'required',
98
- 'shoes' => 'required',
99
- ]);
100
-
101
- $employee = new Employee;
102
- $employee->employee_id = $request->input('employee_id');
103
- $employee->employee_name = $request->input('employee_name');
104
- $employee->office = $request->input('office');
105
- $employee->employee_image = $request->file('employee_image')->store('public/employee_image');
106
-
107
- $employee->save();
108
-
109
- $goods = new Goods;
110
- $goods->uniform = $request->input('uniform');
111
- $goods->winter_clothes = $request->input('winter_clothes');
112
- $goods->shoes = $request->input('shoes');
113
- $goods->other = $request->input('other');
114
- $goods->memo = $request->input('memo');
115
- $goods->employee_id = $employee->id;
116
- $goods->save();
117
-
118
- return redirect(route('employee_create.index'))->with('flash_message','社員を登録しました');
26
+ lrwxrwxrwx 1 root root 44 Jul 24 06:49 storage -> /var/www/html/laravel-app/storage/app/public
119
- }
120
- }
121
- }
122
- ```
123
-
124
- ## ■Employee.php(モデル)
125
- ```namespace App;
126
- use IlluminateSupportFacadesDB;
127
- use Illuminate\Database\Eloquent\Model;
128
-
129
- class Employee extends Model
130
- {
131
-
132
- protected $fillable = ['id','emlpoyee_id','employee_name','office','employee_image'];
133
-
134
- protected $guarded = array('id');
135
-
136
- public function goods()
137
- {
138
- return $this->hasMany(Goods::class);
139
- }
140
- }
141
- ```
142
- ## ■create_employees_table.php(マイグレーション)
143
- ```<?php
144
-
145
- use Illuminate\Database\Migrations\Migration;
146
- use Illuminate\Database\Schema\Blueprint;
147
- use Illuminate\Support\Facades\Schema;
148
-
149
- class CreateEmployeesTable extends Migration
150
- {
151
- public function up()
152
- {
153
- Schema::create('employees', function (Blueprint $table) {
154
- $table->bigIncrements('id');
155
- $table->unsignedBigInteger('employee_id');
156
- $table->string('employee_name');
157
- $table->string('office');
158
- $table->string('employee_image')->nullable();
159
- $table->timestamps();
160
- });
161
- }
162
- public function down()
163
- {
164
- Schema::dropIfExists('employees');
165
- }
166
- }
167
27
  ```