2
我一直試圖在登錄後執行用戶模型中的方法。我的理解是您執行以下操作:Auth::user()->foo();
經過身份驗證後調用用戶模型會產生錯誤調用未定義的方法Illuminate Auth GenericUser
由於某種原因,這是行不通的。
守則User.php
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
protected $table = 'users';
protected $hidden = array('password', 'remember_token');
public function foo(){
return "foo";
}
}
守則routes.php
<?php
Route::get('/', function(){
return View::make('hello');
});
Route::get('users', function(){
if (Auth::attempt(array('email' => '[email protected]', 'password' => 'Tom')))echo 'Auth-true';
echo Auth::id();
if(Auth::check())echo 'checked';
Auth::user()->foo();
});
呼應驗證:: ID()和驗證:檢查()都工作,驗證:用戶() - > FOO( );失敗
錯誤消息
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Call to undefined method Illuminate\Auth\GenericUser::foo()
我有驅動程序設置爲數據庫,謝謝 – K3NN3TH