私はlaravelの初心者ですので、間違いかもしれません。 laravelとtymondesigns/jwt-auth を使用してユーザーを確認します。私はこのチュートリアルComplete JWT-AUTH api with Laravelを見ていて、すべての手順、tymonパッケージのインストールとログインの手順に従っています。しかし、私はこのエラーが発生しています。私は以下のコードを投稿し、他のファイルからもっと多くのコードが必要かどうか教えてください。Laravel 5.4:JWTAuth、EloquentUserProvider.phpのErrorException
ErrorException in EloquentUserProvider.php line 120: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User given
これは私のユーザモデルである:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $hidden = ["password"];
protected $fillable = [
"id",
"name",
"password",
"mobile_number",
"gender",
"age",
"company_name",
"profile_image",
"email"
];
}
?>
私がUserControllerでこの私ApiAuthController.phpある
use JWTAuth;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Exceptions\JWTException;
class ApiAuthController extends Controller
{
public function authenticate(){
$credentaials = request()->only('email', 'password');
print_r($credentaials);
try {
$token = JWTAuth::attempt($credentaials);
if(!$token){
return response()->json(['error'=>'invalid credentaials'], 401);
}
} catch (JWTException $e) {
return response()->json(['error'=>'something went wrong'], 500);
}
return response()->json(['token'=>$token], 200);
}
}
ユーザーストア機能:
public function store(Request $request)
{
$payload = json_decode($request->payload, true);
$validator = Validator::make($payload, $this->rules);
if ($validator->passes()) {
$user = (new User())->fill($payload);
if($user->save()){
$response = [
"msg" => "User created",
"link" => "/api/users/" . $user->id
];
return response()->json($response, 200);
}
$response = [
"msg" => "An error occured"
];
return response()->json($response, 404);
}
else {
return response()->json($validator->messages(), 404);
}
}
ユーザーを保存するには要求、ペイロードは鍵であり、v ALUEはJSONオブジェクトである、小さなサンプルオブジェクトは以下の通りです:
payload={
"name": "Alexa",
"email": "[email protected]",
"password":"12345",
"gender": "Male",
"age": 24
}
このエラーに関連しないヒント:あなたの入力可能なフィールドから「id」を削除すると、あなたのIDを大量に割り当てることはできません。また、パスワードは隠し配列内になければなりません。充填可能なものではない。クレデンシャルの代わりにクレデンシャルを使用します。 – Christophvh