質問編集履歴
2
Controllerのコードを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -113,4 +113,62 @@
|
|
113
113
|
{
|
114
114
|
protected $table = 'dtb_product_image';
|
115
115
|
}
|
116
|
+
```
|
117
|
+
|
118
|
+
AuthController.php
|
119
|
+
```php
|
120
|
+
<?php
|
121
|
+
|
122
|
+
namespace App\Http\Controllers\Auth;
|
123
|
+
use App\User;
|
124
|
+
use Carbon\Carbon;
|
125
|
+
use Illuminate\Http\Request;
|
126
|
+
use App\Http\Controllers\Controller;
|
127
|
+
use Illuminate\Support\Facades\Auth;
|
128
|
+
class AuthController extends Controller
|
129
|
+
{
|
130
|
+
public function login(Request $request) {
|
131
|
+
$request->validate([
|
132
|
+
'email' => 'required|string|email',
|
133
|
+
'password' => 'required|string',
|
134
|
+
//'remember_me' => 'boolean'
|
135
|
+
]);
|
136
|
+
$credentials = request(['email', 'password']);
|
137
|
+
if(!Auth::attempt($credentials))
|
138
|
+
return response()->json([
|
139
|
+
'message' => 'Unauthorized'
|
140
|
+
], 401);
|
141
|
+
$user = $request->user();
|
142
|
+
$tokenResult = $user->createToken('Personal Access Token');
|
143
|
+
$token = $tokenResult->token;
|
144
|
+
if ($request->remember_me)
|
145
|
+
$token->expires_at = Carbon::now()->addWeeks(1);
|
146
|
+
$token->save();
|
147
|
+
return response()->json([
|
148
|
+
'access_token' => $tokenResult->accessToken,
|
149
|
+
'token_type' => 'Bearer',
|
150
|
+
'expires_at' => Carbon::parse(
|
151
|
+
$tokenResult->token->expires_at
|
152
|
+
)->toDateTimeString()
|
153
|
+
]);
|
154
|
+
}
|
155
|
+
|
156
|
+
public function logout(Request $request)
|
157
|
+
{
|
158
|
+
$request->user()->token()->revoke();
|
159
|
+
return response()->json([
|
160
|
+
'message' => 'Successfully logged out'
|
161
|
+
]);
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Get the authenticated User
|
166
|
+
*
|
167
|
+
* @return [json] user object
|
168
|
+
*/
|
169
|
+
public function user(Request $request)
|
170
|
+
{
|
171
|
+
return response()->json($request->user());
|
172
|
+
}
|
173
|
+
}
|
116
174
|
```
|
1
追記を記入しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -75,4 +75,42 @@
|
|
75
75
|
Illuminate\Database\Eloquent\RelationNotFoundException: Call to undefined relationship [ticket] on model [App\Customer]. in file /var/www/html/siro/vendor/laravel/framework/src/Illuminate/Database/Eloquent/RelationNotFoundException.php on line 34
|
76
76
|
```
|
77
77
|
|
78
|
-
dtb_product_imageテーブルのfile_nameカラムを取得するには何処を修正すればいいのでしょうか。
|
78
|
+
dtb_product_imageテーブルのfile_nameカラムを取得するには何処を修正すればいいのでしょうか。
|
79
|
+
|
80
|
+
### 追記
|
81
|
+
|
82
|
+
エンティティに以下のコードを追加しましたが、取得する事はできませんでした。
|
83
|
+
お手数ですが問題点を教えて頂けないでしょうか。
|
84
|
+
|
85
|
+
Product.php
|
86
|
+
```php
|
87
|
+
<?php
|
88
|
+
|
89
|
+
namespace App;
|
90
|
+
|
91
|
+
use Illuminate\Database\Eloquent\Model;
|
92
|
+
|
93
|
+
class Product extends Model
|
94
|
+
{
|
95
|
+
protected $table = 'dtb_product';
|
96
|
+
|
97
|
+
public function image()
|
98
|
+
{
|
99
|
+
return $this->hasone('App\Product_Image', 'product_id', 'id');
|
100
|
+
}
|
101
|
+
}
|
102
|
+
```
|
103
|
+
|
104
|
+
Product_Image.php
|
105
|
+
```php
|
106
|
+
<?php
|
107
|
+
|
108
|
+
namespace App;
|
109
|
+
|
110
|
+
use Illuminate\Database\Eloquent\Model;
|
111
|
+
|
112
|
+
class Product_Image extends Model
|
113
|
+
{
|
114
|
+
protected $table = 'dtb_product_image';
|
115
|
+
}
|
116
|
+
```
|