php - 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;
}
}
解决方案
删除use Sluggable, SluggableEngine, SluggableScopeHelpers
;
并将其替换为use Sluggable, SluggableScopeHelpers
;
它应该工作。
推荐阅读
- java - JOrbis 无法从 JAR 中读取 ogg 文件
- r - 舍入数字并在 R 中保留科学记数法
- javascript - 使用highcharts-vue时如何重排HighCharts?
- html - 无序列表不会在我的图片下方移动
- python - 我想将我的 CNN 模型的具体预测更改为概率
- batch-file - 如何在 VS Code 中将切换注释从 @REM 更改为 REM
- javascript - 多次调用 Office.js 并等待完成所有
- python - Heroku 上的 django 网站部署上没有这样的表
- ios - 在 react-native 中使用 Siri 意图
- python - 为什么此代码不适用于特定类型的数据?