pboivin/laravel-blade-bind-attributes
最新稳定版本:v0.2.0
Composer 安装命令:
composer require pboivin/laravel-blade-bind-attributes
包简介
Attribute unpacking for Laravel Blade component tags
README 文档
README
⚠ EXPERIMENTAL ⚠
This package adds support for @bind attributes in Blade component tags. The new attribute allows you to extract all keys from a given array as component props:
@php $header = [ 'title' => 'Lorem ipsum', 'secondaryTitle' => 'Dolor sit amet', ]; @endphp <x-header @bind="$header" class="my-header" />
This is equivalent to:
<x-header :title="$header['title']" :secondary-title="$header['secondaryTitle']" class="my-header" />
Requirements
- PHP >= 8.1
- Laravel >= 9.x
Installation
composer require pboivin/laravel-blade-bind-attributes
php artisan view:clear
Caveats
With class-based components, make sure to include a @props() directive in your template, even when you are defining the props on the component class:
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>
Development
Test suite (phpunit)
composer run test
Code formatting (pint)
composer run format
License
This is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-31