Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 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 Answer

0 votes
by (71.8m points)

Remove
use Sluggable, SluggableEngine, SluggableScopeHelpers;

and replace use Sluggable, SluggableScopeHelpers;

it will work


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...