PHPackages                             midwestern-interactive/blade-directive-helpers - 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. midwestern-interactive/blade-directive-helpers

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

midwestern-interactive/blade-directive-helpers
==============================================

A collection of Blade Directive Helpers to speed up tasks that are common in Blade templates

1.0.6(8y ago)013PHPPHP ^7.0

Since Oct 17Pushed 8y agoCompare

[ Source](https://github.com/Midwestern-Interactive/blade-directive-helpers)[ Packagist](https://packagist.org/packages/midwestern-interactive/blade-directive-helpers)[ RSS](/packages/midwestern-interactive-blade-directive-helpers/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

Blade Helpers
=============

[](#blade-helpers)

*A collection of Blade Directive to speed up tasks that are common in Blade templates*

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

[](#installation)

1. Move the two included `php` files in to `/app/Providers/`.
2. In `/config/app.php` add

```
        /**
         * Custom Service Providers
         */
        App\Providers\BladeDirectiveProvider::class,
        App\Providers\BladeIfDirectiveProvider::class,
```

3. The above will enable the directives in your Blade templates.

**Since Blade tags get compiled into normal PHP inside your template you are REQUIRED to clear your compiled views via a `php artisan view:clear` call!**

Usage
-----

[](#usage)

### Blade Helper Directives

[](#blade-helper-directives)

\*A Blade directive is just a shorter syntax to generate markup.

#### `asset`

[](#asset)

\*The `@asset` directive provides chache busting functionality by appending the Unix timestamp value of the files modified timestamp

```

```

The above markup produces...

```

```

This effectively eliminates unwanted caching since any time `app.css` is deployed the files modified timestamp will get updated and consequently change the `v=` value in the url for the css file.

**A CSS example is shown above, but this can be used for ANY local file you wish to have cache busting enabled on**

#### `icon`

[](#icon)

*The `@icon` directive allows you to generate the full syntax for a simple icon (more complex icons i.e. layered, rotating, etc will still need to be written out). Font-awesome is the assumed font library.*

In its simplest form you just pass the name of the icon.

```
@icon('envelope')Messages

```

You can also pass two additinal parameters. The second parameter is the `$provider` so an example would be *glyphicon*. This should be the class that gets added to the element. The third parameter you can use the the tag type (`i`, `span`, etc). **If you need access to the third tag you are required to pass the second!**

A full example of this would be...

```
@icon('envelope', 'glyphicon', 'span') Messages

```

### Blade If Directives

[](#blade-if-directives)

*Blade "If" directives allow you to shorthand an `if` statment that you'd normally have to write out. These inherently have an `else` block available*

#### `hasPermission`

[](#haspermission)

*The has permission directive allows you to wrap markup that you only want displayed if a user has a given permission. Can be used in place of the `@can` directive.*

```
@hasPermission('manage-users')
    Manage Users
@else

@endhasPermission
...
```

#### `isInRole`

[](#isinrole)

*Checks that the user is in a given Role*

```
...
@isInRole('admin')
    Manage Users
@else

@endisInRole
...
```

#### `isActive`

[](#isactive)

*This is used to see if a link is currently the active link*

```
Home
```

This directive calls the `Request::is(...)` function internally so you can pass any string to check that would work there. i.e. `@isActive('users*)` would match `/users` as wells `/users/manage/1`

As with all if directives there is an `else` block available. i.e. `
