pboivin / laravel-blade-bind-attributes
此包已被废弃且不再维护。没有建议的替代包。
Laravel Blade组件标签的属性解包
v0.2.0
2023-02-26 16:35 UTC
Requires
- php: >=8.1
- laravel/framework: ^9.0|^10.0
Requires (Dev)
- laravel/pint: ^1.2
- orchestra/testbench: ^8.0
README
⚠ 实验 ⚠
此包增加了对Blade组件标签中@bind
属性的支持。新的属性允许您从给定的数组中提取所有键作为组件属性
@php $header = [ 'title' => 'Lorem ipsum', 'secondaryTitle' => 'Dolor sit amet', ]; @endphp <x-header @bind="$header" class="my-header" />
这相当于
<x-header :title="$header['title']" :secondary-title="$header['secondaryTitle']" class="my-header" />
要求
- PHP >= 8.1
- Laravel >= 9.x
安装
composer require pboivin/laravel-blade-bind-attributes
php artisan view:clear
注意事项
对于基于类的组件,确保在模板中包含@props()
指令,即使您在组件类中定义了属性
app/View/Components/Header.php
class Header extends Component { public function __construct( public $title = 'Hello', public $secondaryTitle = 'World' ){} public function render() { return view('components.header'); } }
resources/views/components/header.blade.php
@props([ 'title', 'secondaryTitle', ]) <div {{ $attributes }}> <h1>{{ $title }}</h1> <h2>{{ $secondaryTitle }}</h2> {{-- ... --}} </div>
开发
测试套件(《phpunit》
composer run test
代码格式(《pint》)
composer run format
许可协议
这是一个开源软件,遵循MIT许可协议。