我将zizaco/confide
与cviebrock/eloquent-sluggable
结合使用。
eloquent-sluggable使用Events::listen('eloquent.saving*')
在保存时/之前生成slu ..
// Cviebrock\EloquentSluggable\SluggableServiceProvider:55
public function registerEvents()
{
$app = $this->app;
$app['events']->listen('eloquent.saving*', function($model) use ($app)
{
$app['sluggable']->make($model);
});
}
由于我切换到Confide进行身份验证,因此无法生成slu ..
我的用户模型只是class User extends ConfideUser
。切换到课程User extends Ardent
或User extends Eloquent
,事件eloquent.saving
将被触发正常。
如果这是一个错误或我遗漏了某些东西,我不会感到害羞。
我的模特:
<?php
use Illuminate\Database\Eloquent\Model;
use Zizaco\Confide\ConfideUser;
class User extends ConfideUser
{
public $autoPurgeRedundantAttributes = true;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* Soft delete
*
* @var boolean
*/
protected $softDelete = true;
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = array(
'nickname',
'password',
'email',
'deleted_at',
'disabled',
'firstname',
'lastname',
'birthday',
// needed by ardent
'email_confirmation',
'password_confirmation'
);
public static $rules = array(
'firstname' => 'required',
'email' => 'required|email|confirmed|unique:users',
'email_confirmation' => 'required',
'nickname' => 'required|min:2|unique:users',
'birthday' => 'date:d.m.Y|before:now',
'password' => 'required|min:5|confirmed',
'password_confirmation' => 'required'
);
public $imageSizes = array(
array(64, 64),
array(250, 250)
);
public static $sluggable = array(
'build_from' => 'nickname',
'save_to' => 'slug',
);
/**
* Roles
*
* @return object
*/
public function roles()
{
return $this->belongsToMany(
'Role',
'role_user'
)
->withTimestamps();;
}
}
答案 0 :(得分:0)
在我看来,这是一个错误:https://github.com/Zizaco/confide/issues/179
作为临时解决方法,您可以在模型中包装beforeSave()
方法而不返回任何内容(!):
public function beforeSave($forced = false)
{
parent::beforeSave($forced);
}