質問編集履歴
2
Controllerのコードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -229,3 +229,119 @@
|
|
229
229
|
}
|
230
230
|
|
231
231
|
```
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
AuthController.php
|
236
|
+
|
237
|
+
```php
|
238
|
+
|
239
|
+
<?php
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
namespace App\Http\Controllers\Auth;
|
244
|
+
|
245
|
+
use App\User;
|
246
|
+
|
247
|
+
use Carbon\Carbon;
|
248
|
+
|
249
|
+
use Illuminate\Http\Request;
|
250
|
+
|
251
|
+
use App\Http\Controllers\Controller;
|
252
|
+
|
253
|
+
use Illuminate\Support\Facades\Auth;
|
254
|
+
|
255
|
+
class AuthController extends Controller
|
256
|
+
|
257
|
+
{
|
258
|
+
|
259
|
+
public function login(Request $request) {
|
260
|
+
|
261
|
+
$request->validate([
|
262
|
+
|
263
|
+
'email' => 'required|string|email',
|
264
|
+
|
265
|
+
'password' => 'required|string',
|
266
|
+
|
267
|
+
//'remember_me' => 'boolean'
|
268
|
+
|
269
|
+
]);
|
270
|
+
|
271
|
+
$credentials = request(['email', 'password']);
|
272
|
+
|
273
|
+
if(!Auth::attempt($credentials))
|
274
|
+
|
275
|
+
return response()->json([
|
276
|
+
|
277
|
+
'message' => 'Unauthorized'
|
278
|
+
|
279
|
+
], 401);
|
280
|
+
|
281
|
+
$user = $request->user();
|
282
|
+
|
283
|
+
$tokenResult = $user->createToken('Personal Access Token');
|
284
|
+
|
285
|
+
$token = $tokenResult->token;
|
286
|
+
|
287
|
+
if ($request->remember_me)
|
288
|
+
|
289
|
+
$token->expires_at = Carbon::now()->addWeeks(1);
|
290
|
+
|
291
|
+
$token->save();
|
292
|
+
|
293
|
+
return response()->json([
|
294
|
+
|
295
|
+
'access_token' => $tokenResult->accessToken,
|
296
|
+
|
297
|
+
'token_type' => 'Bearer',
|
298
|
+
|
299
|
+
'expires_at' => Carbon::parse(
|
300
|
+
|
301
|
+
$tokenResult->token->expires_at
|
302
|
+
|
303
|
+
)->toDateTimeString()
|
304
|
+
|
305
|
+
]);
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
public function logout(Request $request)
|
312
|
+
|
313
|
+
{
|
314
|
+
|
315
|
+
$request->user()->token()->revoke();
|
316
|
+
|
317
|
+
return response()->json([
|
318
|
+
|
319
|
+
'message' => 'Successfully logged out'
|
320
|
+
|
321
|
+
]);
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
/**
|
328
|
+
|
329
|
+
* Get the authenticated User
|
330
|
+
|
331
|
+
*
|
332
|
+
|
333
|
+
* @return [json] user object
|
334
|
+
|
335
|
+
*/
|
336
|
+
|
337
|
+
public function user(Request $request)
|
338
|
+
|
339
|
+
{
|
340
|
+
|
341
|
+
return response()->json($request->user());
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
```
|
1
追記を記入しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -153,3 +153,79 @@
|
|
153
153
|
|
154
154
|
|
155
155
|
dtb_product_imageテーブルのfile_nameカラムを取得するには何処を修正すればいいのでしょうか。
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
### 追記
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
エンティティに以下のコードを追加しましたが、取得する事はできませんでした。
|
164
|
+
|
165
|
+
お手数ですが問題点を教えて頂けないでしょうか。
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
Product.php
|
170
|
+
|
171
|
+
```php
|
172
|
+
|
173
|
+
<?php
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
namespace App;
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
use Illuminate\Database\Eloquent\Model;
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
class Product extends Model
|
186
|
+
|
187
|
+
{
|
188
|
+
|
189
|
+
protected $table = 'dtb_product';
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
public function image()
|
194
|
+
|
195
|
+
{
|
196
|
+
|
197
|
+
return $this->hasone('App\Product_Image', 'product_id', 'id');
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
```
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
Product_Image.php
|
208
|
+
|
209
|
+
```php
|
210
|
+
|
211
|
+
<?php
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
namespace App;
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
use Illuminate\Database\Eloquent\Model;
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
class Product_Image extends Model
|
224
|
+
|
225
|
+
{
|
226
|
+
|
227
|
+
protected $table = 'dtb_product_image';
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
```
|