googleshokry / laravel-blade-directives
实用的 Blade 指令
Requires
- php: >=5.6
- laravel/framework: ^5.5
Requires (Dev)
- orchestra/testbench: ~3.5
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-29 05:09:22 UTC
README
一组优秀的 Laravel Blade 指令。
安装
您可以通过 composer 安装此包
composer require googleshokry/laravel-blade-directives
用法
@istrue
仅当 $variable
存在且为真时显示。
@istrue($variable) This will be echoed @endistrue
或者当您想快速输出时
@istrue($variable, 'This will be echoed')
@isfalse
与 @istrue
相同,但检查是否存在和为假。
@isfalse($variable) This will be echoed @endisfalse
@isnull
仅当 $variable
为 null 时显示。
@isnull($variable) This will be echoed @endisnull
@isnotnull
与 @isnull
相同,但 $variable
不是 null 时显示。
@isnotnull($variable) This will be echoed @endisnotnull
@dump 和 @dd
@dump($var) @dd($var)
@mix
创建一个 HTML 元素,用于 Laravel-Mix 的 css 或 js。
@mix('/css/app.css') @mix('/js/app.js')
输出
<link rel="stylesheet" href="{{ mix('/css/app.css') }}"> <script src="{{ mix('/js/app.js') }}"></script>
@style
创建一个 <style>
元素或带有 css 路径的 <link>
元素。
@style body { background: black } @endstyle @style('/css/app.css')
@script
创建一个带有或没有 js 路径的 <script>
元素。
@script alert('hello world') @endscript @script('/js/app.js')
@inline
在视图中内联加载 css 或 js 文件的全部内容。
@inline('/js/manifest.js')
@pushonce
与 @push
相同,但内容只包含一次。对于可重复的块非常有用。
第一个参数必须遵循语法 stack-name:group-name
。
@pushonce('js:foobar') <script src="{{ asset('/js/foobar.js') }}"></script> @endpushonce
包括带有标准 @stack
指令的推送
@stack('js')
@routeis
检查当前路由名称是否等于给定的参数。您可以使用通配符,例如 blog.post.*
。
@routeis('webshop.checkout') Do something only on the checkout @endrouteis
@routeisnot
检查当前路由名称是否不等于给定的参数。您可以使用通配符,例如 blog.post.*
@routeisnot('webshop.checkout') Do something only if this is not the checkout @endrouteisnot
@instanceof
检查第一个参数是否是第二个参数的实例。
@instanceof($user, 'App\User') User is an instance of App\User @endinstanceof
@typeof
检查参数是否为特定类型。
@typeof($text, 'string') Text is a string @endtypeof
@repeat
重复指定次数的内容。
@repeat(3) Iteration #{{ $iteration }} @endrepeat
@fa, @fas, @far, @fal, @fab, @mdi, @glyph
快速输出 Font Awesome、Material Design Icons 或 Glyphicon 图标。
@fa('address-book', 'optional-extra-class') // for Font Awesome 5 (solid, regular, light, brand): @fas('address-book', 'optional-extra-class') @far('address-book', 'optional-extra-class') @fal('address-book', 'optional-extra-class') @fab('address-book', 'optional-extra-class') // for Material Design Icons @mdi('account', 'optional-extra-class') // for Glyphicons @glyph('glass', 'optional-extra-class')
@data
从数组输出数据属性。
@data(['testing' => 123])
测试
composer test
贡献
欢迎贡献,感谢大家 :)
关于 GoogleShokry
GoogleShokry 是来自荷兰的一个小型团队。我们为网络开发创建(开源)工具,并在 Medium 上撰写相关主题。您可以在 Twitter 上关注我们,给我们买啤酒 或在 Patreon 上支持我们。
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件。