benjamincrozat/laravel-blade-sugar

Add syntactic sugar to your templates.

4.0.12 2019-09-03 15:58 UTC

README

Build Status Latest Stable Version License Total Downloads

Laravel Blade Sugar

Add syntactic sugar to your templates.

Requirements

This package is tested to run on PHP 5.6+ and Laravel 5.1+. Note that on older Laravel versions, some directives can't be used (like @mix) since the associated helper didn't exist yet.

Installation

composer require benjamincrozat/laravel-blade-sugar

Usage

If you're on Laravel 5.4 or older, add the service provider in your config/app.php file:

'providers' => [

    BC\Laravel\BladeSugar\ServiceProvider::class,

],

Available directives

@action()

Generates an URL for a given controller action.

<a href="@action('SomeController@someAction', ['someParameter' => 'someValue'])">Some Link</a>

More in the official Laravel documentation: https://laravel.com/docs/helpers#method-action

@asset()

Renders an asset using the current URL scheme:

<img src="@asset('img/photo.jpg')">

More in the official Laravel documentation: https://laravel.com/docs/helpers#method-asset

@secureAsset()

Renders an asset using HTTPS:

<img src="@secureAsset('img/photo.jpg')">

More in the official Laravel documentation: https://laravel.com/docs/helpers#method-secure-asset

@config()

Displays a config value.

@config('foo.bar')
@config('foo.bar', 'Default value')
@config(['foo.bar' => 'Value'])

More in the official Laravel documentation: https://laravel.com/docs/helpers#method-config

@checked()

Automatically adds a checked attribute if your condition returns true.

<input type="radio" value="foo" @checked('foo' === $value)> <label>Choice #1</label>
<input type="radio" value="bar" @checked('bar' === $value)> <label>Choice #2</label>
<input type="radio" value="baz" @checked('baz' === $value)> <label>Choice #3</label>

@gravatar()

Automatically displays a Gravatar from a given email address.

<img src="@gravatar('homer@simpson.com')">

@markdown()

Renders Markdown using Parsedown, which is built in Laravel.

@markdown('**Hello, World!**')

@mix()

Returns the path to a versioned Mix file.

<link rel="stylesheet" src="@mix('/path/to/some/styles.css')">
<script src="@mix('/path/to/some/script.js')"></script>

More in the official Laravel documentation: https://laravel.com/docs/helpers#method-mix

@old()

Retrieves an old input value flashed into the session:

<input type="text" name="foo" value="@old('foo')">

More in the official Laravel documentation: https://laravel.com/docs/helpers#method-old

@route()

Generates a URL for the given named route.

<a href="@route('posts.index')">Blog</a>
<a href="@route('posts.show', $post)">{{ $post->title }}</a>
<a href="@route('posts.show', $post, true)">{{ $post->title }}</a>

More in the official Laravel documentation: https://laravel.com/docs/helpers#method-route

@selected()

Adds a selected attribute if your condition returns true.

<select>
    <option value="draft" @selected('draft' === $post->status)>Draft</option>
    <option value="published" @selected('published' === $post->status)>Published</option>
</select>

@storageUrl()

Generates a URL from any supported storage.

<img src="@storageUrl($post->illustration)">
<img src="@storageUrl($post->illustration, 's3')">

@title()

Generates a title tag.

@title('My Page Title')
@title($optional_title, 'Fallback Title')

@url()

Generates a fully qualified URL to the given path.

<a href="@url('user/profile')">Register</a>
<a href="@url('user/profile', 'john-doe')">Register</a>
<a href="@url('some/other/route', [
    'foo' => 'bar',
    ...
])">Register</a>

More in the official Laravel documentation: https://laravel.com/docs/helpers#method-url

@with()

This directive let you assign new variables inside your Blade template.

@with('foo', 'bar')

{{ $foo }}

Instead of:

@php $foo = 'bar'; @endphp

{{ $foo }}

License

WTFPL