相关疑难解决方法(0)

如何在我的Laravel 5应用程序中使用Illuminate\Support\Str :: slug?

我正在做以下事情

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

php laravel laravel-5

16
推荐指数
3
解决办法
2万
查看次数

标签 统计

laravel ×1

laravel-5 ×1

php ×1