Domanda

I'm using Sentry 2.1 for authentication.

My User Model:

<?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']);
  }
}

My login function:

$credentials = array(
  'email'    => Input::get('email'),
  'password' => Input::get('password')
);
if (Auth::attempt($credentials))
{
  $user = Sentry::authenticate($credentials, $remember);
  return Redirect::to('/');
}

The reason why I'm using Auth::attempt and then Sentry::authenticate is because I am migrating from an old database to a new one, so I attach a hook/listener on auth.attempt so I can process checking for old password.

Now, after I'm logged in, I can't access the full_name accessor attribute.

$user = Sentry::getUser();
echo $user->full_name; // results in NULL

I think I'm missing a small thing here but I just can't find that missing piece.

Thanks for the help!

È stato utile?

Soluzione

did you edit config of Sentry (dir: /app/config/packages/cartalyst/sentry/config.php") ??

from

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

to

'model' => 'App\Models\User',
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top