fomvasss/laravel-blocks
最新稳定版本:1.5.0
Composer 安装命令:
composer require fomvasss/laravel-blocks
包简介
Universal blocks system for Laravel (static & dynamic content)
README 文档
README
Universal blocks system for Laravel (static & dynamic content).
Installation
Install the package via composer:
composer require fomvasss/laravel-blocks
Publish and run the migrations with:
php artisan vendor:publish --provider="Fomvasss\Blocks\ServiceProvider"
php artisan migrate
Add to filesystems.php disk config (for cache images):
'disks' => [ //... 'blocks' => [ 'driver' => 'local', 'root' => storage_path('app/public/blocks'), 'url' => env('APP_URL').'/storage/blocks', 'visibility' => 'public', ], ],
Usage
The Eloquent model for relations must has the Trait HasBlocks:
namespace App\Models; use Fomvasss\Blocks\Models\HasBlocks; class PageModel extends Model { use HasBlocks; //... }
Use facede
\Block::setAttrs(['sort' => 'desc'])->init('some-1', 'slug')->getBlock(); \Block::init('contacts')->getData('phone'); \Block::init('slider')->getDataSort('slides');
For prepare dynamic block content, place your hendlers in dir app/Blocks/...
You can quickly generate one using the artisan command:
php artisan make:block ContactsBlockHandler
This will create a new class based on the block.stub template inside app/Blocks.
Example app/Blocks/ContactsBlockHandler.php:
<?php namespace App\Blocks; use Fomvasss\Blocks\Contracts\BlockHandlerInterface; use Illuminate\Database\Eloquent\Model; class ContactsBlockHandler implements BlockHandlerInterface { public static function getType(): string { return 'contacts'; } public function handle(Model $block, array $attrs = []): array { return [ 'email' => config('app.email'), 'address' => $block->getContent('address', ''), 'phone' => preg_replace('/[^0-9]/si', '', $block->getContent('phone', '')), ] + $attrs; } }
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 296
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-05