@yield(Str :: limit('text',10))不起作用-Laravel

我当前的代码

<meta name="description" content="Download @yield('description_custom')">

我想为我的“ description_custom”设置限制

我试过了

<meta name="description" content="Download @yield(Str::limit('description_custom', 10))">

但是我收到500错误

评论
{醉相思}
{醉相思}

问题解决了

<meta name="description" content="{{\Illuminate\Support\Str::limit($description,160) }}">
点赞
评论
zquam
zquam

You can edit a variable with came from 'description_custom' with View::getSections() In you blade file:

{{ View::getSections()['description_custom'] = str_limit(View::getSections()['description_custom'],10,'...')  }}

或者如果您在laravel 7中,也可以尝试

{{ View::getSections()['description_custom'] = Str::limit('description_custom', 10) }}

而你的元数据仍然是

<meta name="description" content="Download @yield('description_custom')">
点赞
评论