Skip to content

stefro/laravel-blade-directives

 
 

Repository files navigation

Laravel Blade Directives

Latest Version on Packagist Total Downloads Software License Build Status

A collection of nice Laravel Blade directives.

Installation

You can install the package via composer:

composer require appstract/laravel-blade-directives

Provider

In Laravel 5.5 the package will autoregister the Service Provider. In older versions, you must add the ServiceProvider to your config/app.php file:

'providers' => [
    ...

    Appstract\BladeDirectives\BladeDirectivesServiceProvider::class

    ...
];

Usage

@istrue

Only show when $variable isset and true.

@istrue($variable)
   This will be echoed
@endistrue

Or when you would like to quickly echo

@istrue($variable, 'This will be echoed')

@isfalse

Same as @istrue but checks for isset and false.

@isfalse($variable)
   This will be echoed
@endisfalse

@dump and @dd

@dump($var)

@dd($var)

@mix

Create a HTML element to your Laravel-Mix css or js.

@mix('/css/app.css')
@mix('/css/app.js')

Output:

<link rel="stylesheet" href="{{ mix('/css/app.css') }}">
<script src="{{ mix('/css/app.js') }}"></script>

@style

Create a <style> element or <link> element with a css path.

@style
    body { background: black }
@endstyle    


@style('/css/app.css')

@script

Create a <script> element with or without a js path.

@script
    alert('hello world')
@endscript


@script('/js/app.js')

@inline

Load the contents of a css or js file inline in your view.

@inline('/js/manifest.js')

@pushonce

Same as @push but will include content one time only. Useful for repeatable blocks.

First parameter must follow the syntax stack-name:group-name.

@pushonce('js:foobar')
    <script src="{{ asset('/js/foobar.js') }}"></script>
@endpushonce

Include pushes with standard @stack directive:

@stack('js')

@routeis

Checks if the current route name is equal to the given parameter.

@routeis('webshop.checkout')
    Do something only on the checkout
@endrouteis

@routeisnot

Checks if the current route name is not equal to the given parameter.

@routeisnot('webshop.checkout')
    Do something only if this is not the checkout
@endrouteisnot

@instanceof

Checks if the first parameter is an instance of the second parameter.

@instanceof($user, App\User)
    User is an instance of App\User
@endinstanceof

@typeof

Checks if the parameter is of a certain type.

@typeof($text, 'string')
    Text is a string
@endtypeof

@repeat

Repeat something a specified amount of times.

@repeat(3)
    Iteration #{{ $iteration }}
@endrepeat

@fa

Quickly output a Font Awesome icon.

@fa('address-book')

Testing

$ composer test

Contributing

Contributions are welcome, thanks to y'all :)

About Appstract

Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on Medium. You can follow us on Twitter, buy us a beer or support us on Patreon.

License

The MIT License (MIT). Please see License File for more information.

About

A collection of nice Laravel Blade directives

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%