【发布时间】:2015-05-30 14:52:54
【问题描述】:
我在做下面的
public function boot(DispatcherContract $events)
{
parent::boot($events);
// set Tag slug
Tag::saving(function($tag)
{
//slugify name
$tag->slug = Str::slug($tag->name);
});
}
当我在 tinker 中运行它时,我收到以下错误:
PHP Fatal error: Class 'App\Providers\Str' not found in /var/www/questions-l5/app/Providers/EventServiceProvider.php on line 35
..但我不知道 Laravel 的导入方式。我是否只需要使用use,我尝试将以下内容添加到 config/app.php 文件中:
'aliases' => [
...
'Str' => 'Illuminate\Support\Str',
.. 不过好像没什么区别。
http://chrishayes.ca/blog/code/laravel-4-generating-unique-slugs-elegantly http://laravel.com/api/5.0/Illuminate/Support/Str.html
【问题讨论】:
-
str_slug($title, $separator);不适合你?