【问题标题】:Using Sentry::getUser(), I can't access model accessors使用 Sentry::getUser(),我无法访问模型访问器
【发布时间】:2014-02-20 19:06:17
【问题描述】:

我正在使用 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

我想我在这里遗漏了一件小东西,但我就是找不到那个遗失的部分。

感谢您的帮助!

【问题讨论】:

  • 我想第一件事是 dd() $user 变量,以确保它是您期望的 User 类的对象。

标签: php laravel laravel-4 cartalyst-sentry


【解决方案1】:

您是否编辑了 Sentry 的配置(目录:/app/config/packages/cartalyst/sentry/config.php")??

来自

'model' => 'Cartalyst\Sentry\Users\Eloquent\User',

'model' => 'App\Models\User',

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多