私はガードを使用してコードと認証されたユーザを作成しましたが、それはapi_token
api_tokenの生成方法は?
/**
* This'll provide login authentication to the user
* @param Request $request
* @return json
*/
public function authenticate(Request $request)
{
//getting and setting locale for the request
$locale = ($request->header('lang-code') == 'KO') ? "ko" : "en";
app()->setLocale($locale);
$credentials = $request->only('email','password');
try {
// verify the credentials and create a token for the user
if (!$token = auth()->attempt($credentials)) {
return response()->json(['success' => parent::FAILURE, 'message' => trans('messages.api.login.failure')],401);
}
} catch (GeneralException $e) {
// something went wrong
return response()->json(['success' => parent::FAILURE, 'message' => trans('messages.api.login.tokenNC')],500);
}
return response()->json(['success' => parent::SUCCESS, 'message' => trans('messages.api.login.success'), 'data' => auth()->user()],200);
}
機能の上に私を提供していませんが正常に動作しているが、私はauth()->guard('api')->user()->api_token
を使用するとき、私はトークン届きません。 api_token
を生成することができないのに、この列は既に私のDB内にあります。
EDITED
ルート/ api.php:
Route::group(['namespace' => "Api\\v1", 'as' => 'api.v1.', 'prefix' => 'v1'], function() {
Route::any('/login', '[email protected]');
});
のconfig/auth.php:
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
それでも採石場を持っている場合は、私に尋ねるか、アップ票と私の答えを受け入れます! – msonowal
あなたの** config/auth.php **はどのようなものですか? –
あなたのルートファイルも –