我正在做以下事情
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
我使用这行代码在我的应用程序上显示下一个帖子标题
<span class="blog-title-next"> {{ $post->nextPost()['title'] }} </span>
Run Code Online (Sandbox Code Playgroud)
如何限制标题名称仅显示前10个字符?
谢谢.
我有一个描述字段,但我只需要在我的刀片页面上显示10个字符.我怎样才能做到这一点?