【问题标题】:Laravel disable slug transltionsLaravel 禁用 slug 翻译
【发布时间】: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 背包项目

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    这就是它的工作方式。每个翻译都有自己的 slug:

    en/test-slug
    ar/تست-سلغ
    

    等等。为什么你需要它正常工作? 作为一种解决方法,您可以在检索时从 slug 中提取本地信息。

    【讨论】:

      猜你喜欢
      • 2019-12-01
      • 1970-01-01
      • 2019-06-18
      • 2022-01-01
      • 1970-01-01
      • 2021-08-21
      • 2020-01-02
      • 1970-01-01
      相关资源
      最近更新 更多