@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')">