質問編集履歴

1

全体のソースコードを追加

2018/04/18 05:28

投稿

TakashiKitamura
TakashiKitamura

スコア8

test CHANGED
File without changes
test CHANGED
@@ -69,3 +69,187 @@
69
69
 
70
70
 
71
71
  ご教授頂けないでしょうか。
72
+
73
+
74
+
75
+ こちらは全体のコードです。
76
+
77
+ ```ここに言語を入力
78
+
79
+ <?php
80
+
81
+
82
+
83
+ namespace App\Http\Controllers;
84
+
85
+
86
+
87
+ use Illuminate\Support\Facades\Cookie;
88
+
89
+ use Illuminate\Support\Facades\DB;
90
+
91
+ use Illuminate\Http\Request;
92
+
93
+
94
+
95
+
96
+
97
+ /**
98
+
99
+ * Class FacilityController
100
+
101
+ *
102
+
103
+ * @package App\Http\Controllers
104
+
105
+ */
106
+
107
+ class SearchGpsController extends Controller {
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+ public function getIndex( Request $request ) {
116
+
117
+
118
+
119
+ $order_by = $request->input( 'order_by', 'updated_at' );
120
+
121
+
122
+
123
+ //-----------------------------------------------------
124
+
125
+ // SQL
126
+
127
+ //-----------------------------------------------------
128
+
129
+
130
+
131
+ $querys = DB::select('fac_plans')
132
+
133
+ ->select(DB::raw(
134
+
135
+ '
136
+
137
+
138
+
139
+ '
140
+
141
+ ));
142
+
143
+ $query = DB::select('
144
+
145
+ SELECT *
146
+
147
+ FROM (
148
+
149
+ SELECT
150
+
151
+ geo_id,
152
+
153
+ shop_num,
154
+
155
+ ASTEXT(geo),
156
+
157
+ GLENGTH(GEOMFROMTEXT(
158
+
159
+ CONCAT(\'LINESTRING(\',
160
+
161
+ 135.506109, \' \', 34.674875, ",",
162
+
163
+ X(geo), \' \', Y(geo),
164
+
165
+ \')\'
166
+
167
+ ))
168
+
169
+ ) AS distance
170
+
171
+ FROM fac_geos
172
+
173
+ ) AS dist
174
+
175
+ JOIN shop ON shop.shop_num = dist.shop_num
176
+
177
+ INNER JOIN conditions ON shop.shop_num = conditions.shop_num
178
+
179
+ INNER JOIN categories ON shop.categories_id = categories.categories_id
180
+
181
+ INNER JOIN medicals ON shop.shop_num = medicals.shop_num
182
+
183
+ INNER JOIN companies ON shop.company_id = companies.company_id
184
+
185
+ WHERE
186
+
187
+ distance <= 0.027
188
+
189
+ ORDER BY shop_img DESC,distance DESC ;
190
+
191
+ ');
192
+
193
+
194
+
195
+
196
+
197
+ $sort = 'desc';
198
+
199
+ if ( $order_by === 'init_cost_min' ) {
200
+
201
+ $sort = 'asc';
202
+
203
+
204
+
205
+ }
206
+
207
+
208
+
209
+ if ( $order_by === 'mth_cost_min' ) {
210
+
211
+ $sort = 'asc';
212
+
213
+ }
214
+
215
+
216
+
217
+ if ( $order_by === 'created_at' ) {
218
+
219
+ $sort = 'desc';
220
+
221
+ }
222
+
223
+
224
+
225
+
226
+
227
+ $result = $query
228
+
229
+ ->orderBy( sprintf( 'shop.%s', $order_by ), $sort )
230
+
231
+ ->paginate( 10 );
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+ return view( 'search.index' )
240
+
241
+ ->with( 'shop_data', $result );
242
+
243
+ }
244
+
245
+
246
+
247
+ }
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+ ```