appstract/laravel-blade-directives

实用的 Blade 指令

1.14.0 2023-06-14 09:08 UTC

README

Latest Version on Packagist Total Downloads Software License Build Status

一组优秀的 Laravel Blade 指令。

安装

您可以通过 composer 安装此包

composer require appstract/laravel-blade-directives

使用方法

@istrue

仅当 $variable 已设置且为 true 时显示。

@istrue($variable)
   This will be echoed
@endistrue

或者当您想快速输出时

@istrue($variable, 'This will be echoed')

@isfalse

@istrue 相同,但检查 isset 和 false。

@isfalse($variable)
   This will be echoed
@endisfalse

@isnull

仅当 $variable 为 null 时显示。

@isnull($variable)
   This will be echoed
@endisnull

@isnotnull

@isnull 相同,但当一个变量不为 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, @fad, @mdi, @glyph

快速输出 Font Awesome、Material Design Icons 或 Glyphicon 图标。

@fa('address-book', 'optional-extra-class')

// for Font Awesome 5 (solid, regular, light, brand, duotone):
@fas('address-book', 'optional-extra-class')
@far('address-book', 'optional-extra-class')
@fal('address-book', 'optional-extra-class')
@fab('address-book', 'optional-extra-class')
@fad('address-book', 'optional-extra-class')

// for Material Design Icons
@mdi('account', 'optional-extra-class')

// for Glyphicons
@glyph('glass', 'optional-extra-class')

@data

输出来自数组的 data 属性。

@data(['testing' => 123])

@haserror

快速输出用于经典 $errors->has('input_name') 以确定是否存在给定字段的错误消息。

@haserror('input_name')
    This input has an error
@endhaserror

@count

输出条目数量。

@count([1,2,3])

@nl2br

\n 替换为 <br>

@nl2br('foo\n bar\n baz\n')

@snake, @kebab, @camel

输出格式化字符串(使用 Laravel 辅助函数)。

@snake('fooBar')
// output: 'foo_bar'

@kebab('fooBar')
// output: 'foo-bar'

@camel('foo bar')
// output: 'fooBar'

测试

composer test

贡献

欢迎贡献,感谢大家 :)

关于 Appstract

Appstract 是来自荷兰的一个小型团队。我们为 Web 开发者创建(开源)工具,并在 Medium 上撰写相关主题。您可以在 Twitter 上关注我们,给我们买杯啤酒在 Patreon 上支持我们

许可

MIT 许可证 (MIT)。有关更多信息,请参阅许可文件