Support the ongoing development of Laravel.io →
Views Blade

I've seen several suggestions on how to create helpers for Blade: Use global functions, create a class with static methods etc.

But I've come up with something different, using the View::share() syntax: http://www.develophp.org/2014/07/laravel-4-blade-helper-functions/

I'd be interested in opinions: Does this feel cleaner to you? I certainly like it.

Last updated 2 years ago.
0

I like it, especially because if you're using a helper class, because you can use a syntax like this:

<select>
    {{ $formHelper->years(1997, 2007) }}
</select>
Last updated 2 years ago.
0

I think I'd still prefer using a macro.

HTML::macro('human_size', function($bytes)
{
    $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];
    for ($i = 0; $bytes > 1024; $i++) {
        $bytes /= 1024;
    }
    return round($bytes, 2).' '.$units[$i];
});

and then calling

{{ HTML::human_size('123456789') }}
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.