PHPackages                             bhuvidya/laravel-blade-helper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. bhuvidya/laravel-blade-helper

ActiveLibrary[Templating &amp; Views](/categories/templating)

bhuvidya/laravel-blade-helper
=============================

A Laravel 5 package to provide an abstraction when creating Blade directives.

v1.0.1(7y ago)112MITPHPPHP &gt;=7.1.0

Since Sep 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/bhuvidya/laravel-blade-helper)[ Packagist](https://packagist.org/packages/bhuvidya/laravel-blade-helper)[ Docs](https://github.com/bhuvidya/laravel-blade-helper)[ RSS](/packages/bhuvidya-laravel-blade-helper/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Laravel Blade Helper
====================

[](#laravel-blade-helper)

[![License](https://camo.githubusercontent.com/78cfebbe55e398759977f5fc46dfb2ff038aab4e203b15d795f5ed10595e3af8/68747470733a2f2f706f7365722e707567782e6f72672f62687576696479612f6c61726176656c2d626c6164652d68656c7065722f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/bhuvidya/laravel-blade-helper)[![Total Downloads](https://camo.githubusercontent.com/889aa40f43929ac35c031f0f1312bb541d9ed54e5c4cfd4e699574e4caf72394/68747470733a2f2f706f7365722e707567782e6f72672f62687576696479612f6c61726176656c2d626c6164652d68656c7065722f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/bhuvidya/laravel-blade-helper)[![Latest Stable Version](https://camo.githubusercontent.com/618c2d1b9d07cd2d959b0ab1b6bc67e018faa4a965b264b1f82d6bcff0719a18/68747470733a2f2f706f7365722e707567782e6f72672f62687576696479612f6c61726176656c2d626c6164652d68656c7065722f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/bhuvidya/laravel-blade-helper)[![Latest Unstable Version](https://camo.githubusercontent.com/50799a0c6c9c13c97b1b9a3a75a0d9bed4c7610a9634741d4d102bce8855cb94/68747470733a2f2f706f7365722e707567782e6f72672f62687576696479612f6c61726176656c2d626c6164652d68656c7065722f762f756e737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/bhuvidya/laravel-blade-helper)

A Laravel 5 package to ease the creation of Blade directives.

**Please note that this package was tested on Laravel 5.6. It should work on &gt;=5.5, but I cannot guarantee it will work on earlier versions. Sorry.**

**BIG KUDOS** to Liam () who proposed this as a pull request on the Laravel Framework ([laravel/framework#24923](https://github.com/laravel/framework/pull/24923)). I really liked the concept so I put his code into a package for others to use if they wanna. This README draws on his explanations in the pull request.

Installation
------------

[](#installation)

Add `bhuvidya/laravel-blade-helper` to your app:

```
$ composer require "bhuvidya/laravel-blade-helper"

```

**If you're using Laravel 5.5 or higher, you don't have to edit `app/config/app.php`.**

Otherwise, edit `app/config/app.php` and add the service provider:

```
'providers' => [
    'BhuVidya\BladeHelper\BladeHelperServiceProvider',
]

```

### Configuration

[](#configuration)

The package comes with its own configuration file, which you can install and tweak in your application:

```
artisan vendor:publish --provider='BhuVidya\BladeHelper\BladeHelperServiceProvider' --tag=config

```

This will install the config file to your app's config directory. It's contents are:

```
return [
    /*
    |--------------------------------------------------------------------------
    | Service instance "name"
    |--------------------------------------------------------------------------
    */
    'instance' => 'bhuvidya.blade_helper',

    /*
    |--------------------------------------------------------------------------
    | You can elect to register an alias for the facade automatically, and give
    | it your own custom class name. Set to false to not register.
    |--------------------------------------------------------------------------
    */
    'facade' => 'BladeHelper',
];

```

As you can see, it's possible to customise the service container instance name, and (probably a bit more useful), get the facade to be loaded automatically, and with your own class name if so desired.

Usage
-----

[](#usage)

Basically this helper provides a neat level of abstraction to the "define a custom Blade directive" process. It's benfit is in allowing the connected function (or closure) to have a well-defined parameter list, without having to do the cruft coding around parsing the raw expression string passed in from Laravel core. This allows you to quickly turn an external function into a Blade directive.

For example, to turn the php function `join` into a directive:

```
// Define the helper directive
BladeHelper::helper('join');

// Use it in a view
@join('|', ['Hello', 'world'])

// Get the compiled result

// See what's echoed
"Hello|world"

```

Admittedly a contrived example, but it gives you the idea.

The second argument can also take a callback. The advantage of a callback here over the Blade::directive(...) method is that the closure can have specific parameters defined instead of just the raw expression passed through. This has several good things that solve a [previous idea](https://github.com/laravel/ideas/issues/1104) Liam brought up:

- Type hint the arguments for the callback
- Manipulate and use the individual arguments when the directive is called, instead of the raw expression as a string
- Define a directive without having to only use it as a proxy to a helper function or class in another part of the application

```
// Define the helper directive
BladeHelper::helper('example', function($a, $b, $c = 'give', $d = 'you') {
    return "$a $b $c $d up";
});

// Use it in a view
@example('Never', 'gonna')

// Get the compiled result

// See what's echoed
"Never gonna give you up"

```

By default, all of the helper directives will echo out their contents to the view when used. This can be disabled by passing false as the third argument.

```
// Define the helper directive
BladeHelper::helper('log', null, false);

// Use it in a view
@log('View loaded...')

// Get the compiled result

// Nothing is echoed

```

In the [pull request](https://github.com/laravel/framework/pull/24923) there was some discussion around whether directives should be used just for code structure, and not presentation. Personally I like custom directives even for "presentation" or "convenience" usage because:

1. It makes template files cleaner, and easier to read
2. Having the code in one place makes it easier to change in the future

As a last example, here is a wrapper for the logic around a FontAwesome 4 icon. There's a bit of boilerplate around it you probably don't want to remember to write every time, and you wouldn't want to `@include` it every time. While it could be a regular function and operate just the same, this is one of those things you'd probably want that bit of syntactic sugar around because of how often it can be used - nor would there be any advantage of it being a regular function or helper as you'd never get any use of it outside views. Also, if you ever decided to tweak the html of the `` element (maybe adding a new `aria` attribute), then you only have to do it in one place.

```
BladeHelper::helper('fa', function(string $iconName, string $text = null, $classes = '') {
    if (is_array($classes)) {
        $classes = join(' ', $classes);
    }

    $text = $text ?? $iconName;

    return "{$text}";
});

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

2804d ago

Major Versions

v0.0.1 → v1.0.02018-09-07

PHP version history (2 changes)v0.0.1PHP &gt;=7.0.0

v1.0.1PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d88c0eb87ca5e69e7db7aaebd5ae9545f913b4890146afe0f2be21d5a5a41793?d=identicon)[bhuvidya](/maintainers/bhuvidya)

---

Top Contributors

[![bhuvidya](https://avatars.githubusercontent.com/u/455707?v=4)](https://github.com/bhuvidya "bhuvidya (6 commits)")

---

Tags

bladelaravelpackagelaravelblade

### Embed Badge

![Health badge](/badges/bhuvidya-laravel-blade-helper/health.svg)

```
[![Health](https://phpackages.com/badges/bhuvidya-laravel-blade-helper/health.svg)](https://phpackages.com/packages/bhuvidya-laravel-blade-helper)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
