我正在做以下事情
public function boot(DispatcherContract $events)
{
parent::boot($events);
// set Tag slug
Tag::saving(function($tag)
{
//slugify name
$tag->slug = Str::slug($tag->name);
});
}
Run Code Online (Sandbox Code Playgroud)
当我在修补程序中运行它时,我收到以下错误:
PHP Fatal error: Class 'App\Providers\Str' not found in /var/www/questions-l5/app/Providers/EventServiceProvider.php on line 35
Run Code Online (Sandbox Code Playgroud)
..但我不知道Laravel导入它的方式.我是否需要使用use,我尝试将以下内容添加到config/app.php文件中:
'aliases' => [
...
'Str' => 'Illuminate\Support\Str',
Run Code Online (Sandbox Code Playgroud)
..但似乎没有太大的区别.
http://chrishayes.ca/blog/code/laravel-4-generating-unique-slugs-elegantly http://laravel.com/api/5.0/Illuminate/Support/Str.html