Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

php - Trait method customizeSlugEngine has not been applied, because there are collisions with other trait methods on AppBaseSluggableModel

Trait method customizeSlugEngine has not been applied, because there are collisions with other trait methods on AppBaseSluggableModel

at app/Base/SluggableModel.php:17

I tried everything, this is project from github, this project: https://github.com/ozdemirburak/laravel-8-simple-cms What is this error, here is code SluggableModel.php:

<?php

namespace AppBase;

use AppBaseTraitsSluggableEngine;
use CviebrockEloquentSluggableSluggable;
use CviebrockEloquentSluggableSluggableScopeHelpers;
use IlluminateDatabaseEloquentModel;

/**
 * AppBaseSluggableModel
 *
 * @method static IlluminateDatabaseEloquentBuilder|AppBaseSluggableModel findSimilarSlugs($attribute, $config, $slug)
 * @method static IlluminateDatabaseEloquentBuilder|AppBaseSluggableModel 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 AppBaseTraits;

use CocurSlugifySlugify;

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 CocurSlugifySlugify $engine
     * @param string $attribute
     * @return CocurSlugifySlugify
     */
    public function customizeSlugEngine(Slugify $engine, $attribute)
    {
        return $this->getTurkishEngine($engine);
    }

    /**
     * @param CocurSlugifySlugify $engine
     *
     * @return CocurSlugifySlugify
     */
    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;
    }
}
question from:https://stackoverflow.com/questions/66064434/trait-method-customizeslugengine-has-not-been-applied-because-there-are-collisi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Remove
use Sluggable, SluggableEngine, SluggableScopeHelpers;

and replace use Sluggable, SluggableScopeHelpers;

it will work


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...