1

私のlaravel 4アプリケーション(http://docs.cartalyst.com/sentry-2/)でSentry2パッケージを使用しています。

Sentry2 ユーザー モデルを拡張する新しいユーザー モデルを作成します。

<?php namespace App\Models;

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends \Cartalyst\Sentry\Users\Eloquent\User implements UserInterface, RemindableInterface {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password');

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }

}

次のコードを実行すると、例外が発生します。

$adminUser = User::create(array(
    'email'       => 'admin@admin.com',
    'password'    => "admin",
    'first_name'  => 'Admin',
    'last_name'   => 'Admin',
    'activated'   => 1,
));

エラー:

 [RuntimeException]
 A hasher has not been provided for the user.
4

4 に答える 4

2

sentry パッケージの構成ファイルを更新する必要があります。

'users' => array(

    /*
    |--------------------------------------------------------------------------
    | Model
    |--------------------------------------------------------------------------
    |
    | When using the "eloquent" driver, we need to know which
    | Eloquent models should be used throughout Sentry.
    |
    */

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

    /*
    |--------------------------------------------------------------------------
    | Login Attribute
    |--------------------------------------------------------------------------
    |
    | If you're the "eloquent" driver and extending the base Eloquent model,
    | we allow you to globally override the login attribute without even
    | subclassing the model, simply by specifying the attribute below.
    |
    */

    'login_attribute' => 'email',

),

と使用Sentry::getUserProvider()->create()方法

    $adminUser = Sentry::getUserProvider()->create(
        array(
            'email'       => 'admin@admin.com',
            'password'    => "admin",
            'first_name'  => 'Admin',
            'last_name'   => 'Admin',
            'activated'   => 1,
        )
    );
于 2013-05-22T23:46:16.853 に答える