2017-09-24 44 views
0

不知道爲什麼我得到這個錯誤...Laravel驗證「調用一個成員函數上的空getReminderToken()」

Call to a member function getRememberToken() on null (View: /home/vagrant/temptools/resources/views/layouts/main.blade.php) (View: /home/vagrant/temptools/resources/views/layouts/main.blade.php) 

我有一個驗證::該刀片頁

上檢查()

我使用https://github.com/invisnik/laravel-steam-auth

路線:

Route::get('login', '[email protected]')->name('login'); 
Route::get('login/handle', '[email protected]')->name('login.handle'); 
Route::post('logout', 'Auth\[email protected]')->name('logout'); 

AuthController:

namespace App\Http\Controllers; 

use Invisnik\LaravelSteamAuth\SteamAuth; 
use App\User; 
use Auth; 

class AuthController extends Controller 
{ 
    /** 
    * The SteamAuth instance. 
    * 
    * @var SteamAuth 
    */ 
    protected $steam; 

    /** 
    * The redirect URL. 
    * 
    * @var string 
    */ 
    protected $redirectURL = '/'; 

    /** 
    * AuthController constructor. 
    * 
    * @param SteamAuth $steam 
    */ 
    public function __construct(SteamAuth $steam) 
    { 
     $this->steam = $steam; 
    } 

    /** 
    * Redirect the user to the authentication page 
    * 
    * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector 
    */ 
    public function redirectToSteam() 
    { 
     return $this->steam->redirect(); 
    } 

    /** 
    * Get user info and log in 
    * 
    * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector 
    */ 
    public function handle() 
    { 
     if ($this->steam->validate()) { 
      $info = $this->steam->getUserInfo(); 

      if (!is_null($info)) { 
       $user = $this->findOrNewUser($info); 

       Auth::login($user, true); 

       return redirect($this->redirectURL); // redirect to site 
      } 
     } 
     return $this->redirectToSteam(); 
    } 

    /** 
    * Getting user by info or created if not exists 
    * 
    * @param $info 
    * @return User 
    */ 
    protected function findOrNewUser($info) 
    { 
     $user = User::where('id', $info->steamID64)->first(); 

     if (!is_null($user)) { 
      return $user; 
     } 

     return User::create([ 
      'name' => $info->personaname, 
      'avatar' => $info->avatarfull, 
      'id' => $info->steamID64 
     ]); 
    } 
} 

應用/用戶:

namespace App; 

use Illuminate\Notifications\Notifiable; 
use Illuminate\Foundation\Auth\User as Authenticatable; 

class User extends Authenticatable 
{ 
    use Notifiable; 

    protected $fillable = [ 
     'id', 'name', 'avatar', 
    ]; 

    protected $hidden = [ 
     'remember_token', 
    ]; 
} 

create_users_table遷移:

use Illuminate\Support\Facades\Schema; 
use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateUsersTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('users', function (Blueprint $table) { 
      $table->bigInteger('id')->unsigned(); 
      $table->string('name'); 
      $table->string('avatar'); 
      $table->rememberToken(); 
      $table->timestamps(); 

      $table->primary('id'); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::dropIfExists('users'); 
    } 
} 

刪除了密碼恢復遷移。

我也得到了錯誤,如果我打的退出路徑:

Call to a member function getRememberToken() on null 

========

展望錯誤,錯誤似乎是在laravel /框架/秒/Illuminate/Auth/EloquentUserProvider.php線67

public function retrieveByToken($identifier, $token) 
{ 
     $model = $this->createModel(); 
     $model = $model->where($model->getAuthIdentifierName(), $identifier)->first(); 
     $rememberToken = $model->getRememberToken(); 
     return $model && $rememberToken && hash_equals($rememberToken, $token) ? $model : null; 
    } 

仍然不知道如何解決它雖然

回答

0

看起來像這個軟件包使用Laravel Auth ...你如何爲你的用戶設置唯一的ID?一般來說,你應該自動增加它們...不要忘記,Laravel的認證依賴於許多約定...看看AuthenticatesUsers特性的一瞥...但需要的字段之一是電子郵件...

trait AuthenticatesUsers 
{ 
    /** 
    * Get the login username to be used by the controller. 
    * 
    * @return string 
    */ 
    public function username() 
    { 
     return 'email'; 
    } 
} 

查看Auth結構,查看默認的'web'guard(查看config目錄中的auth.php作爲起點......)。


public function up() 
    { 
     Schema::create('users', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('name'); 
      $table->string('email')->unique(); //Unique ID for login in laravel? The AuthenticatesUser trait uses email as username... 
      $table->string('password'); 
      $table->string('avatar'); 
      $table->rememberToken(); 
      $table->timestamps(); 
     }); 
    } 

希望這有助於...

0

進入此功能父:

public function retrieveByToken($identifier, $token){ 
    $model = $this->createModel(); 
    $model = $model->where($model->getAuthIdentifierName(), $identifier)->first(); 
    $rememberToken = $model->getRememberToken(); 
    return $model && $rememberToken && hash_equals($rememberToken, $token) ? $model : null; 
} 

轉儲模型和$標識,

創建一個模型行標識符,它會被修復!

相關問題