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

3.0.1 2018-05-17 07:54 UTC


Build Status Latest Stable Version License Total Downloads

Laravel Blade Sugar

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


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:

<!-- Renders as <img src="http(s)://"> -->
<img src="@asset('img/photo.jpg')">

More in the official Laravel documentation:


Renders an asset using HTTPS:

<!-- Renders as <img src=""> -->
<img src="@secureAsset('img/photo.jpg')">

More in the official Laravel documentation:


Automatically adds a checked attribute if the condition returns true.

<input type="checkbox" @checked($value === 'something')>


Automatically displays a Gravatar from a given email address.

<img src="@gravatar($email)">


Automatically parses Markdown.

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


Display a paginator only if there is more than one page.

So you do this:


Instead of this:

@if ($articles->hasMorePages())
    {{ $articles->links() }}


Just the route() helper wrapped in a Blade directive.

<a href="@route('articles.index')">Blog</a>
<a href="@route('', $article->slug)">{{ $article->title }}</a>
<a href="@route('', ['slug' => $article->slug])">{{ $article->title }}</a>


Automatically adds a selected attribute if the condition returns true.

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


Generates a URL from any supported storage.

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


Just 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',


You can now do this:

@with('category', $article->category)
@with('username', $article->user->name)

by {{ $username }} in <a href="@route('', $category->slug)">{{ $category->name }}</a>

Instead of:

by {{ $article->user->name }} in <a href="@route('', $article->category->slug)">{{ $article->category->name }}</a>