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)

1.5.0(4mo ago)3386↓50%1MITPHPPHP ^8.0

Since Oct 5Pushed 4mo 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 1mo ago

READMEChangelogDependencies (2)Versions (8)Used By (0)

Laravel Blocks package
======================

[](#laravel-blocks-package)

[![License](https://camo.githubusercontent.com/2e2c9bfdba53b31b8458649f4becc2d866f837d868562fd69dd61786a7dbf7b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f666f6d76617373732f6c61726176656c2d626c6f636b732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-blocks)[![Build Status](https://camo.githubusercontent.com/72d26ca3549a0229716d749900376c6609655e999f92058e35ff4a79b0dbcb58/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f666f6d76617373732f6c61726176656c2d626c6f636b732e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/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)[![Quality Score](https://camo.githubusercontent.com/c7f30411f2f0864d7667c9ea4128db97e47609bf9d998b2cfcb4476973f0c221/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f666f6d76617373732f6c61726176656c2d626c6f636b732e7376673f7374796c653d666f722d7468652d6261646765)](https://scrutinizer-ci.com/g/fomvasss/laravel-blocks)

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

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

[](#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
-----

[](#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`:

```
