laravel 4からlaravel 5に移行しました。ユーザーモデルをlaravel 5 User Modelと互換性があるように変更しました。 Laravel 4におけるユーザモデルはそのようなものです:Laravel 5の "User Model"機能が動作しません
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
// some model relation functions..
...
public function getLocationId()
{
return $this->location_id;
}
}
私はそれを修正して、新しいユーザー・モデルは今そのようなものです:
namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\Model as Eloquent;
class User extends Eloquent implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
// some model relation functions (some changes for namespace)
...
public function getLocationId()
{
return $this->location_id;
}
}
しかし、getLocationId方法について問題があります。次の行はエラーになります。
$auth_location_id = Auth::user()->getLocationId();
これはエラーです:
BadMethodCallException in Builder.php line 2508:
Call to undefined method Illuminate\Database\Query\Builder::getLocationId()
にはどうすれlaravel 5に方法が互換性を持たせることができますか?おかげで..
更新:
$auth_location_id = Auth::user()->getLocationId;
作品だが、空を返します!
以下の行は正しく動作します。
私の理解することで$auth_user_id = Auth::user()->getAuthIdentifier();
laravelのバージョンは何ですか、あなたは更新しようとしていますか? 5.4?もしそうなら、このリンク[https://github.com/laravel/laravel/blob/master/app/User.php] (https://github.com/laravel/laravel/blob/master/app/User.php)に従ってください。 ) – zgabievi
@zgabieviはい、5.4です。 – horse