PHPackages                             fomvasss/laravel-blocks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fomvasss/laravel-blocks

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fomvasss/laravel-blocks
=======================

Universal blocks system for Laravel (static &amp; dynamic content)

2.6.5(1mo ago)3573↑128.6%1MITPHPPHP ^8.1

Since Oct 5Pushed 1mo agoCompare

[ Source](https://github.com/fomvasss/laravel-blocks)[ Packagist](https://packagist.org/packages/fomvasss/laravel-blocks)[ Docs](https://github.com/fomvasss/laravel-blocks)[ RSS](/packages/fomvasss-laravel-blocks/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (10)Versions (21)Used By (0)

Laravel Blocks
==============

[](#laravel-blocks)

[![License](https://camo.githubusercontent.com/2e2c9bfdba53b31b8458649f4becc2d866f837d868562fd69dd61786a7dbf7b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f666f6d76617373732f6c61726176656c2d626c6f636b732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-blocks)[![Latest Stable Version](https://camo.githubusercontent.com/ceb442ab8bb4c2ccf5a51a089e2a316b977976aaf6b8b7c6a5b9ca6602d53364/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6d76617373732f6c61726176656c2d626c6f636b732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-blocks)[![Total Downloads](https://camo.githubusercontent.com/7a0dc89d13dcaeab4803b7b844675b29254ac539dacfbb79f7c4820ed7a1afc7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f6d76617373732f6c61726176656c2d626c6f636b732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-blocks)

Universal content-blocks system for Laravel — static (JSON) and dynamic (handler-driven).

> Ukrainian: [README.uk.md](README.uk.md)

---

Requirements
------------

[](#requirements)

- PHP ^8.1 · Laravel ^10 / ^11 / ^12 / ^13

Installation
------------

[](#installation)

```
composer require fomvasss/laravel-blocks
php artisan vendor:publish --provider="Fomvasss\Blocks\ServiceProvider"
php artisan migrate
```

---

Facade
------

[](#facade)

```
// Get prepared block model
\Block::init('contacts')->getBlock();

// Read a value from merged data
\Block::init('contacts')->getData('phone');

// Read nested value (dot-notation)
\Block::init('hero')->getData('slides.0.title');

// Read sorted array (by item weight)
\Block::init('slider')->getDataSort('slides');

// Pass runtime attrs to the dynamic handler
\Block::setAttrs(['limit' => 5])->init('news')->getData('items');

// JSON resources
\Block::getBlockResource('hero');
\Block::getBlocksResource(['hero', 'contacts']);          // indexed
\Block::getBlocksResource(['hero', 'contacts'], 'slug');  // keyed by slug
```

---

Dynamic Block Handlers
----------------------

[](#dynamic-block-handlers)

Create a handler class in `app/Blocks/` — it is auto-discovered on boot.

```
php artisan make:block ContactsBlockHandler
```

```
