我正在做以下事情
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
最佳答案
我认为你不需要在这里创建别名,所以只需添加
use Illuminate\Support\Str;
到你的模型。
关于php - 如何在我的 Laravel 5 应用程序中使用 Illuminate\Support\Str::slug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29281013/