【发布时间】:2019-01-09 21:18:28
【问题描述】:
使用 10 月 cms 的 build 422 和 Rainlab 博客插件,博客文章不可能有非英文的 slug,每次都说“slug 格式无效。”
是否有解决此限制的解决方案或变通方法?
【问题讨论】:
标签: laravel octobercms
使用 10 月 cms 的 build 422 和 Rainlab 博客插件,博客文章不可能有非英文的 slug,每次都说“slug 格式无效。”
是否有解决此限制的解决方案或变通方法?
【问题讨论】:
标签: laravel octobercms
我建议您关注extending guide of octobercms 并扩展它。 这样您就可以安全地更新博客插件,而不必担心再次重新编辑它,或者当您必须重新安装 octobercms 时不得不记住对其进行编辑。
use Rainlab\Blog\Models\Post;
class Plugin extends PluginBase
{
public function boot()
{
// Extend post Model
Post::extend(function($model) {
// Only do stuff when validation is triggered
$model->bindEvent('model.beforeValidate', function() use ($model) {
// Find the regex holding value to avoid hardcoding array index
foreach($model->rules as $key => $value) {
if(strpos($value, 'regex:') !== false) {
// unset validation rule containing the regex.
unset($model->rules[$key]);
break;
}
}
}
});
}
}
【讨论】:
您可以像这样在模型文件中评论以下代码。
路径 :: Plugins/rainlab/blog/models/Post.php
public $rules = [
'title' => 'required',
// 'slug' => ['required', 'regex:/^[a-z0-9\/\:_\-\*\[\]\+\?\|]*$/i', 'unique:rainlab_blog_posts'],
'content' => 'required',
'excerpt' => ''
];
【讨论】: