benjamincrozat/laravel-blade-sugar

This package is abandoned and no longer maintained. No replacement package was suggested.

Add syntactic sugar to your templates.

5.0.0 2020-03-03 13:54 UTC

This package is auto-updated.

Last update: 2023-03-14 08:56:09 UTC


README

Build Status Latest Stable Version License Total Downloads

Laravel Blade Sugar

Add syntactic sugar to your templates.

Installation

composer require benjamincrozat/laravel-blade-sugar

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