首页 > 解决方案 > Trait 方法 customizeSlugEngine 尚未应用,因为与 App\Base\SluggableModel 上的其他 trait 方法有冲突

问题描述

Trait 方法 customizeSlugEngine 尚未应用,因为与 App\Base\SluggableModel 上的其他 trait 方法有冲突

在 app/Base/SluggableModel.php:17

我尝试了一切,这是来自 github 的项目,这个项目: ozdemirburak / laravel-8-simple-cms | GitHub 这是什么错误,这里是代码SluggableModel.php:

<?php

namespace App\Base;

use App\Base\Traits\SluggableEngine;
use Cviebrock\EloquentSluggable\Sluggable;
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Base\SluggableModel
 *
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Base\SluggableModel findSimilarSlugs($attribute, $config, $slug)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Base\SluggableModel whereSlug($slug)
 * @mixin \Eloquent
 */
class SluggableModel extends Model
{
    use Sluggable, SluggableEngine, SluggableScopeHelpers;

    /**
     * @var array
     */
    protected $guarded = ['created_at', 'id'];

    /**
     * @return array
     */
    public function sluggable()
    {
        return [
            'slug' => [
                'source'   => 'title',
                'onUpdate' => true
            ]
        ];
    }
}

SlugabbleEngine.php:

<?php

namespace App\Base\Traits;

use Cocur\Slugify\Slugify;

trait SluggableEngine
{
    /**
     * Currently, eloquent-sluggable does not provide activeRuleset function, so to do it on your own for any language
     * with following the key value rule pairs can be found within the link below.
     *
     * @link https://github.com/cocur/slugify/blob/3b29d43b0c0d6af590f998ddf096e6d8aaeb6634/src/RuleProvider/DefaultRuleProvider.php#L784
     *
     * @param \Cocur\Slugify\Slugify $engine
     * @param string $attribute
     * @return \Cocur\Slugify\Slugify
     */
    public function customizeSlugEngine(Slugify $engine, $attribute)
    {
        return $this->getTurkishEngine($engine);
    }

    /**
     * @param \Cocur\Slugify\Slugify $engine
     *
     * @return \Cocur\Slugify\Slugify
     */
    protected function getTurkishEngine(Slugify $engine)
    {
        $engine->addRule('Ç', 'C');
        $engine->addRule('Ğ', 'G');
        $engine->addRule('İ', 'I');
        $engine->addRule('Ş', 'S');
        $engine->addRule('Ö', 'O');
        $engine->addRule('Ü', 'U');
        $engine->addRule('ğ', 'g');
        $engine->addRule('ı', 'i');
        $engine->addRule('ş', 's');
        $engine->addRule('ö', 'o');
        $engine->addRule('ü', 'u');
        return $engine;
    }
}

标签: phplaravelcontent-management-system

解决方案


删除use Sluggable, SluggableEngine, SluggableScopeHelpers

并将其替换为use Sluggable, SluggableScopeHelpers;

它应该工作。


推荐阅读