質問編集履歴
4
回答を受けての追記③
title
CHANGED
File without changes
|
body
CHANGED
@@ -102,4 +102,46 @@
|
|
102
102
|
他のページでも似たように先生の情報を取る
|
103
103
|
→ajax使用するためjs側にてjson形式にする
|
104
104
|
→そのjsonを利用してhtmlに記載すると表示される
|
105
|
-
(**history.teacher.teacher_images[0].name** のように記載(vue.js))
|
105
|
+
(**history.teacher.teacher_images[0].name** のように記載(vue.js))
|
106
|
+
|
107
|
+
回答を受けての追記③
|
108
|
+
---
|
109
|
+
```
|
110
|
+
//こちらが授業可能な先生情報を取ってくるSQL文
|
111
|
+
$available_teachers = Reservation_calender::where('date', '=', $date)
|
112
|
+
->where(function($query) use ($user_id){
|
113
|
+
$query->where('user_id', '=', NULL);
|
114
|
+
})->with(['teacher.teacherImages' => function($query){//relationのまたそのrelation
|
115
|
+
$query->where('profile', '=', 1)->latest('created_at');
|
116
|
+
}])->get();
|
117
|
+
|
118
|
+
//こんな感じでbladeファイルに値を渡します
|
119
|
+
return view('mypage.main')->with([
|
120
|
+
'available_teachers' => $available_teachers,
|
121
|
+
]);
|
122
|
+
|
123
|
+
|
124
|
+
//bladeファイルのscriptタグ内にてJSON化
|
125
|
+
var available_teachers = @json($available_teachers);
|
126
|
+
|
127
|
+
//html内にて画像の表示→表示される
|
128
|
+
<img class="thumb img-circle" :src="'/images/teachers/'+ available_teacher.teacher.teacher_images[0].name" alt="profile" width=110 height=110>
|
129
|
+
```
|
130
|
+
|
131
|
+
```
|
132
|
+
//こちらが今回質問させていただいた所のSQL文
|
133
|
+
$histories = Reservation_calender::where('user_id', '=' ,$user_id)
|
134
|
+
->where('date', '<' ,$date)
|
135
|
+
->with('time')
|
136
|
+
->with(['teacher.teacherImages' => function($query){//relationのまたそのrelation
|
137
|
+
$query->where('profile', '=', 1)->latest('created_at');
|
138
|
+
}])->latest('date')->get();
|
139
|
+
|
140
|
+
//同じように値を渡す
|
141
|
+
return view('mypage.history')->with([
|
142
|
+
'histories' => $histories,
|
143
|
+
]);
|
144
|
+
|
145
|
+
//画像表示(teacherImagesとする必要有)
|
146
|
+
<img class="thumb img-circle" src="/images/teachers/{{$history->teacher->teacherImages[0]->name}}" alt="profile" width=70 height=70>
|
147
|
+
```
|
3
回答を受けての追記②
title
CHANGED
File without changes
|
body
CHANGED
@@ -76,4 +76,30 @@
|
|
76
76
|
</div>
|
77
77
|
</li>
|
78
78
|
@endforeach
|
79
|
-
```
|
79
|
+
```
|
80
|
+
|
81
|
+
回答を受けての追記②
|
82
|
+
---
|
83
|
+
```
|
84
|
+
//サーバ側でsql取得できるように設定
|
85
|
+
$histories = Reservation_calender::where('user_id', '=' ,$user_id)
|
86
|
+
->where('date', '<' ,$date)
|
87
|
+
->with('time')
|
88
|
+
->with(['teacher.teacherImages' => function($query){
|
89
|
+
$query->where('profile', '=', 1)->latest('created_at');
|
90
|
+
}])->latest('date')->toSql();//元々は ->get();
|
91
|
+
|
92
|
+
var_dump($histories);
|
93
|
+
```
|
94
|
+
```
|
95
|
+
//実行結果
|
96
|
+
'select * from `reservation_calenders` where `user_id` = ? and `date` < ? order by `date` desc'
|
97
|
+
```
|
98
|
+
|
99
|
+
とろうとしていないようですね。。しかしなぜlogには出力されるのか謎ですが。。
|
100
|
+
|
101
|
+
ちなみに参考になるか分かりませんが、
|
102
|
+
他のページでも似たように先生の情報を取る
|
103
|
+
→ajax使用するためjs側にてjson形式にする
|
104
|
+
→そのjsonを利用してhtmlに記載すると表示される
|
105
|
+
(**history.teacher.teacher_images[0].name** のように記載(vue.js))
|
2
回答を受けての追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -56,4 +56,24 @@
|
|
56
56
|
なぜネストしたteacher_imagesの情報はとってこれているのに、htmlに表示させようとすると何も表示されないのか不明です。
|
57
57
|
よろしくお願いします。
|
58
58
|
|
59
|
-
(またmodelでのrelation設定など、追記してほしいコードがあればおっしゃってください。)
|
59
|
+
(またmodelでのrelation設定など、追記してほしいコードがあればおっしゃってください。)
|
60
|
+
|
61
|
+
回答を受けての追記
|
62
|
+
---
|
63
|
+
```
|
64
|
+
@foreach($histories as $history)
|
65
|
+
<li>
|
66
|
+
<div class="detail">
|
67
|
+
<div class="detail-img">
|
68
|
+
<img class="thumb img-circle" src="/images/teachers/{{$history->teacher->teacher_images[0]->name}}" alt="profile" width=70 height=70>//最終的にはファイル名をこのようにlaravelからとってきたい
|
69
|
+
</div>
|
70
|
+
<div class="detail-txt">
|
71
|
+
<div class="date">{{$history->date}}</div>
|
72
|
+
<div class="time">{{$history->time->time}}</div>
|
73
|
+
<div class="name"><a href=""></a>{{$history->teacher->name}}</div>
|
74
|
+
{{$history->teacher->teacher_images}}//この部分browser上では何も表示されない
|
75
|
+
</div>
|
76
|
+
</div>
|
77
|
+
</li>
|
78
|
+
@endforeach
|
79
|
+
```
|
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,8 +48,8 @@
|
|
48
48
|
}
|
49
49
|
```
|
50
50
|
|
51
|
-
コメントで書き込んだ通りですが、teacher_imagesのnameを使用させたい、しかし```{{$histories->teacher->
|
51
|
+
コメントで書き込んだ通りですが、teacher_imagesのnameを使用させたい、しかし```{{$histories->teacher->teacher_images[0]->name}}```とするが```Trying to get property 'name' of non-object```のエラー
|
52
|
-
→そこで```{{$histories->teacher->
|
52
|
+
→そこで```{{$histories->teacher->teacher_images}}```とし、確認すると何もhtml上に表示されない。
|
53
53
|
|
54
54
|
また```{{$histories->time->time}}```は16:00-17:00と表示されます
|
55
55
|
|