benjamincrozat / laravel-blade-sugar
为您的模板添加语法糖。
Requires
- php: ^7.2.5
- illuminate/contracts: ^7.0
- illuminate/support: ^7.0
Requires (Dev)
- orchestra/testbench: ^5.0
- phpunit/phpunit: ^8.5
README
Laravel Blade Sugar
为您的模板添加语法糖。
安装
composer require benjamincrozat/laravel-blade-sugar
可用的指令
- @action()
- @asset()
- @secureAsset()
- @checked()
- @config()
- @gravatar()
- @markdown()
- @mix()
- @old()
- @route()
- @selected()
- @storageUrl()
- @title()
- @url()
- @with()
@action()
为给定的控制器动作生成URL。
<a href="@action('SomeController@someAction', ['someParameter' => 'someValue'])">Some Link</a>
更多官方Laravel文档: https://laravel.net.cn/docs/helpers#method-action
@asset()
使用当前URL方案渲染资产。
<img src="@asset('img/photo.jpg')">
更多官方Laravel文档: https://laravel.net.cn/docs/helpers#method-asset
@secureAsset()
使用HTTPS渲染资产。
<img src="@secureAsset('img/photo.jpg')">
更多官方Laravel文档: https://laravel.net.cn/docs/helpers#method-secure-asset
@config()
显示配置值。
@config('foo.bar') @config('foo.bar', 'Default value') @config(['foo.bar' => 'Value'])
更多官方Laravel文档: https://laravel.net.cn/docs/helpers#method-config
@checked()
如果条件返回true,则自动添加checked
属性。
<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()
自动显示给定电子邮件地址的Gravatar。
<img src="@gravatar('homer@simpson.com')">
@markdown()
使用内置的Parsedown渲染Markdown。
@markdown('**Hello, World!**')
@mix()
返回版本化Mix文件的路径。
<link rel="stylesheet" src="@mix('/path/to/some/styles.css')"> <script src="@mix('/path/to/some/script.js')"></script>
更多官方Laravel文档: https://laravel.net.cn/docs/helpers#method-mix
@old()
检索闪入会话的旧输入值。
<input type="text" name="foo" value="@old('foo')">
更多官方Laravel文档: https://laravel.net.cn/docs/helpers#method-old
@route()
为给定的命名路由生成一个URL。
<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>
更多详情请参考官方Laravel文档:https://laravel.net.cn/docs/helpers#method-route
@selected()
如果条件返回true,则添加selected
属性。
<select> <option value="draft" @selected('draft' === $post->status)>Draft</option> <option value="published" @selected('published' === $post->status)>Published</option> </select>
@storageUrl()
从任何支持的存储中生成一个URL。
<img src="@storageUrl($post->illustration)"> <img src="@storageUrl($post->illustration, 's3')">
@title()
生成一个标题标签。
@title('My Page Title') @title($optional_title, 'Fallback Title')
@url()
生成指向给定路径的完全限定的URL。
<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>
更多详情请参考官方Laravel文档:https://laravel.net.cn/docs/helpers#method-url
@with()
此指令允许你在Blade模板内部分配新变量。
@with('foo', 'bar') {{ $foo }}
而不是
@php $foo = 'bar'; @endphp {{ $foo }}