【发布时间】:2017-04-02 12:25:49
【问题描述】:
我正在尝试使用 slug 保存我的组模型,但它一直在使用未翻译版本的名称保存我的 slug。
有没有办法强制它使用输入值?
这是模型:
class Group extends Model
{
use CrudTrait;
use Sluggable, SluggableScopeHelpers;
use HasTranslations;
protected $table = 'groups';
protected $primaryKey = 'id';
protected $fillable = ['name', 'slug'];
protected $hidden = ['pivot'];
protected $translatable = ['name'];
public $timestamps = true;
*/
public function users()
{
return $this->belongsToMany(User::class);
}
/**
* Return the sluggable configuration array for this model.
*
* @return array
*/
public function sluggable()
{
return [
'slug' => [
'source' => 'name'
],
];
}
}
现在当我输入一个名字时,例如test 这会将我的 slug 值保存为 {"en":"{\"en\":\"test\"}"}
而不是普通的test 有人知道我可能做错了什么吗?
我也在使用 Laravel 背包项目
【问题讨论】: