How to pass a custom function to a Laravel Blade template?

后端 未结 1 1488
野趣味
野趣味 2020-12-25 14:10

I have a custom function and I want to pass it in a blade template. Here is the function:

function trim_characters( $text, $length = 45, $append = \'&hel         


        
相关标签:
1条回答
  • 2020-12-25 14:52

    You don't have to pass anything to blade. If you define your function, you can use it from blade.


    1. Create a new app/helpers.php file.
    2. Add your trim_characters function to it.
    3. Add that file to your composer.json file.
    4. Run composer dump-autoload.

    Now just use the function directly in blade:

    {{ trim_characters($string) }}
    
    0 讨论(0)
提交回复
热议问题