← Back to Plugins
  • Fabricator
  • Fabricator
  • Fabricator

Fabricator

Plugin information

by Z3d0X • 13 stars

Admin panel Developer tool Kit

Block-Based Page Builder Skeleton for your Filament Apps

Support

#fabricator on Discord

Views

952

License

MIT

Documentation

Introduction

What is Filament Fabricator? Filament Fabricator is simply said a block-based page builder skeleton. Filament Fabricator takes care of the PageResource & frontend routing, so you can focus on what really matters: your Layouts & Page Blocks.

Installation

Once you have Filament Admin Panel configured. You can install this package via composer:

composer require z3d0x/filament-fabricator

After that run the install command: (this will publish the config & migrations)

php artisan filament-fabricator:install

To get started create a Layout and then Page Blocks

Layouts

Creating a Layout

Use the following command to create a new Layout:

php artisan make:filament-fabricator-layout DefaultLayout

This will create the following Layout class:

use Z3d0X\FilamentFabricator\Layouts\Layout;
 
class DefaultLayout extends Layout
{
protected static ?string $name = 'default';
}

and its corresponding blade component:

@props(['page'])
<x-filament-fabricator::page-blocks :blocks="$page->blocks" />

You may edit this layout blade file however you want, as long as you are using the filament-fabricator::page-blocks to show the page blocks

Pro tip: Use the $page instance to build your layout

Page Blocks

Creating a Page Block

Use the following command to create a new Page Block:

php artisan make:filament-fabricator-page-block MyBlock

This will create the following Page Block class (& its corresponding blade component view):

use Filament\Forms\Components\Builder\Block;
use Z3d0X\FilamentFabricator\PageBlocks\PageBlock;
 
class MyBlock extends PageBlock
{
public static function getBlockSchema(): Block
{
return Block::make('my-block')
->schema([
//
]);
}
 
public static function mutateData(array $data): array
{
return $data;
}
}

Page Block Schema

Define you block schema in this method:

public static function getBlockSchema(): Block

You may use any Fields to make up your schema.

Pro tip: You can conditionally allow blocks based on a layout using:

Block::make('foo')
->visible(fn ($get) => $get('../layout') == 'special')

Mutate Data

By default, your blade component will receive raw data from all the fields as props

Example:

//Given the following schema
public static function getBlockSchema(): Block
{
return Block::make('my-block')
->schema([
TextInput::make('name'),
]);
}
{{-- Your blade component would receive the following props --}}
@props([
'name'
])

However you may customize this behavior using:

//`$data` is the raw block data.
public static function mutateData(array $data): array

The array keys from this would be your blade component props.

Example:

public static function mutateData(array $data): array
{
return ['foo' => 'bar'];
}
@props([
'foo'
])
 
@dump('foo') // 'bar'

Page Resource

Customize Navigation

You may use the following methods in the boot() of a ServiceProvider to customize the navigation item of PageResource

use Z3d0X\FilamentFabricator\Resources\PageResource;
 
PageResource::navigationGroup('Blog');
PageResource::navigationSort(1);
PageResource::navigationIcon('heroicon-o-cube');

Authorization

To enforce policies, after generating a policy, you would need to register \Z3d0X\FilamentFabricator\Models\Page to use that policy in the AuthServiceProvider.

<?php
 
namespace App\Providers;
 
use App\Policies\PagePolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Z3d0X\FilamentFabricator\Models\Page;
 
class AuthServiceProvider extends ServiceProvider
{
protected $policies = [
Page::class => PagePolicy::class,
];
//...
}

If you are using Shield just register the PagePolicy generated by it