fomvasss/laravel-blocks

Universal blocks system for Laravel (static & dynamic content)

Installs: 7

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/fomvasss/laravel-blocks

1.3.0 2025-10-06 09:40 UTC

This package is auto-updated.

Last update: 2025-10-06 09:40:30 UTC


README

License Build Status Latest Stable Version Total Downloads Quality Score

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 dinamic block content, place your hendlers in dir 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.