認証には Sentry 2.1 を使用しています。
私のユーザーモデル:
<?php namespace App\Models;
use Eloquent;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends \Cartalyst\Sentry\Users\Eloquent\User implements UserInterface, RemindableInterface {
/* Sentry Defaults omitted for brevity */
public function children()
{
return $this->hasMany('App\Models\Children');
}
public function getFullNameAttribute()
{
return trim($this->attributes['first_name'] . ' ' . $this->attributes['last_name']);
}
}
私のログイン機能:
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if (Auth::attempt($credentials))
{
$user = Sentry::authenticate($credentials, $remember);
return Redirect::to('/');
}
Auth::attempt を使用してから Sentry::authenticate を使用する理由は、古いデータベースから新しいデータベースに移行するためです。古いパスワードのチェックを処理できるように、auth.attempt にフック/リスナーをアタッチします。 .
ログインした後、full_name アクセサー属性にアクセスできません。
$user = Sentry::getUser();
echo $user->full_name; // results in NULL
ここで小さなものが欠けていると思いますが、欠けている部分が見つかりません。
助けてくれてありがとう!