2017-09-02 35 views
0

JWT認証を使用して登録とログインのコードを記述しました。このコードでは、登録機能はうまく動作しますが、ログイン機能は動作しません。ログイン機能が見つからないクラス「を照らし\財団\認証\ユーザー」などのエラーを促しクラス 'Illuminate Foundation Auth User'が見つかりませんJWT Auth Laravel

私のユーザモデルは私のUserControllerでは

class UsersController extends Controller 
{ 

    public function login() 
    { 
     $credentials = request()->only('user_name','password'); 
     try{ 
      $token = JWTAuth::attempt($credentials); 
      if($token){ 
       return response()->json(['error'=>'invalid_credentials'],401); 
      } 
     } 
     catch(JWTException $e){ 
      return response()->json(['error'=>'something went wrong'],500); 
     } 
     return response()->json(['token'=>$token],200); 
    } 

    public function register() 
    { 
     $user_name = request()->user_name; 
     $password = request()->password; 
     $user = User::create([ 
      'user_name'=>$user_name, 
      'password'=>bcrypt($password) 
     ]); 

     $token = JWTAuth::fromUser($user); 

     return response()->json(['token'=>$token],200); 
    } 
} 

ログイン機能である

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 
use Illuminate\Foundation\Auth\User as Authenticatable; 
class User extends Authenticatable 
{ 
    protected $table = 'users'; 
    public $timestamps = false; 
    protected $primaryKey = 'user_name'; 
    protected $fillable = ['user_name','password']; 
} 

あるエラーなどを示しています

Class 'Illuminate\Foundation\Auth\User' not found 

答えて

0

問題は私のユーザモデルに存在し、私は

<?php 

namespace App; 

use Illuminate\Auth\Authenticatable; 
use Illuminate\Database\Eloquent\Model; 
use Illuminate\Auth\Passwords\CanResetPassword; 
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; 
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; 

class User extends Model implements AuthenticatableContract, CanResetPasswordContract 
{use Authenticatable, CanResetPassword; 

    // 
    protected $table = 'users'; 
    public $timestamps = false; 
    protected $primaryKey = 'user_name'; 
    protected $fillable = ['user_name','c_name','accessibility_level','password','role','contact_number','address']; 
} 
0

あなたのコントローラでは、モデル "ユーザー"の追加を忘れてしまったようです名前空間宣言下にそれ、またはそれはIlluminate\Foundation\Auth\User

use\App\User; 

との競合だとあなたは次のことを実行する必要があります。

composer update 
composer dump-autoload 
+0

それを解決うん、私はユーザーモデルを使いました。しかし、エラーが存在する – Muthu

+0

Uの作曲家の依存関係を更新しましたか?編集した回答を確認してください – Sletheren

+0

まだ動作していません – Muthu

関連する問題