Some useful sugar for your Laravel Blade templates to keep 'em DRY and clean.

4.0.4 2018-07-26 08:54 UTC


Build Status Latest Stable Version License Total Downloads

Laravel Blade Sugar

Add syntaxic sugar to Laravel Blade to keep your templates DRY and clean.


This package is tested to run on PHP 5.6+ and Laravel 5.4+.


composer require benjamincrozat/laravel-blade-sugar


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

'providers' => [



Available directives


Renders an asset using the current URL scheme:

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

More in the official Laravel documentation:


Renders an asset using HTTPS:

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

More in the official Laravel documentation:


Automatically adds a checked attribute if your condition returns true.

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


Automatically displays a Gravatar from a given email address.

<img src="@gravatar('')">


Renders Markdown using Parsedown, which is built in Laravel.

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


Echos out the path to your Laravel Mix generated asset.

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


The route() helper wrapped in a Blade directive.

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


Adds a selected attribute if your condition returns true.

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


Generates a URL from any supported storage.

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


Generates a title tag depending on the arguments you pass.

<!-- Generates `<title>My Page Title</title>` -->
@title('My Page Title')

<!-- Generates `<title>Default Title</title>` -->
@title(null, 'Default Title')


The url() helper wrapped in a Blade directive.

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


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

@with('foo', 'bar')

{{ $foo }}

Instead of:

<?php $foo = 'bar'; ?>

{{ $foo }}