Truncate string in Laravel blade templates

后端 未结 11 1115
死守一世寂寞
死守一世寂寞 2020-12-07 15:28

Is there a truncate modifier for the blade templates in Laravel, pretty much like Smarty?

I know I could just write out the actual php in the template but i\'m looki

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 15:47

    To keep your code DRY, and if your content comes from your model you should adopt a slightly different approach. Edit your model like so (tested in L5.8):

    description, 10, '...');
        }
    }
    ?>
    

    Then in your view :

    {{ $comment->short_description }}
    

提交回复
热议问题