Giter Site home page Giter Site logo

z3d0x / filament-fabricator Goto Github PK

View Code? Open in Web Editor NEW
228.0 7.0 43.0 1.71 MB

Block-Based Page Builder Skeleton for your Filament Apps

Home Page: https://filamentphp.com/plugins/fabricator

License: MIT License

PHP 69.53% Blade 30.47%
filamentphp laravel-filament laravel-package page-builder hacktoberfest

filament-fabricator's People

Contributors

danielbehrendt avatar dependabot[bot] avatar devhoussam1998 avatar flolanger avatar github-actions[bot] avatar homaeee avatar jvkassi avatar ksimenic avatar laravel-shift avatar lucasgiovanny avatar mohamedsabil83 avatar mrlinnth avatar muhamadselim avatar pboivin avatar ribesalexandre avatar viraljetani avatar voltra avatar witaway avatar z3d0x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

filament-fabricator's Issues

Undefined array key "data"

Good day,

There is an issue with this package especially if you are dealing with data outside of the normal Fabricator process.

Let me explain:

I am building blocks as usual but some of the blocks just need data from a model. The documentation states you can do something like this:

return ['foo' => 'bar']

Sometimes it works, and sometimes it does not and returns the above error. I wish this could work.

This is a great package idea.

The block:

schema([ Placeholder::make('') ->content('Please manage under support management') ]); } public static function mutateData(array $data): array { $data = [ 'donors' => Donor::all() ]; return $data; } } The error: ErrorException PHP 8.1.10 9.52.6 Undefined array key "data" ![image](https://user-images.githubusercontent.com/80934965/233768457-0e8c8c9a-8e47-42da-90ac-7ab86b7762e1.png)

Fabricator overrides application routes.

Goodday,

As mentioned on Twitter, Fabricator overrides application routes. The only route which works is the "/admin" route to access filament if installed in an existing project. One can always change this behaviour in the config file, not too sure what the implications thereof will be as I have not fully tested it. You mentioned that application routes should take priority over fabricator routes. Kindly look into this. Thanks a mill.

Lazy loading violation on Subpages in strict mode

Description

A common practice in laravel applications is to have Model::shouldBeStrict() checks active in non-prod environments:
https://laravel.com/docs/10.x/eloquent#configuring-eloquent-strictness.
Currently, when strict mode is activated, a LazyLoadingViolationException is thrown in:
Z3d0X\FilamentFabricator\FilamentFabricatorManager::setPageUrl()
in the line if (filled($page->children)) when attempting to save a SubPage (a page with parent) from the filament admin panel.

Reproduction steps

  1. Activate strict mode by adding Model::shouldBeStrict(); to the boot() function of the AppServiceProvider.php
    public function boot()
    {
        Model::shouldBeStrict(); // should normally only be active in non-prod environments
    }
  1. Create a Page and a Child Page through the filament admin panel. When saving the Child Page, the Exception will be thrown

Further comments:

The error does not happen if the line if (filled($page->children)) is replaced with if ($page->children()->count() > 0 && filled($page->children)), which seems to suggest that the Violation is not - strictly speaking - a lazy loading violation, but a missing attribute call violation.

Using Fabricator with other models

Hey, great plugin!

Is it possible to use the Fabricator with multiple models? would like to use it with pages and posts.. but didnt see anything in the documentation.

thanks

Issue with Laravel Jetstream

Hi,

When you try to use this package with a layout extend by Laravel JetStram default layout. You got a Javascript error :

Uncaught (in promise) Component not found: JJ8Yux7OzeM3ZVAnkGOG

Steps to reproduce :

  • Install a fresh Laravel app
  • Install Filament
  • Install Laravel Jetstream
  • Install Fabricator
  • Try to preview a created page and after try to make an action

I've tried with theses steps and got this error. Is seems we can not use the preview with a template which contains livewire components.

EDIT : When I remove @livewire('navigation-menu') it works perfectly. I've tried to use Filament Hook like this :

{{ \Filament\Support\Facades\FilamentView::renderHook('filament-fabricator::menu') }}
FilamentView::registerRenderHook(
    'filament-fabricator::menu',
    fn (): string => Blade::render('@livewire(\'navigation-menu\')'),
);

But got the same error

Any solution to fix this ?

Thanks,

Problem during migration when custom table name is set

I changed fabricator table name so it couldn't conflict with "pages" table I want to create later. Got an error during migration.

The config config/filament-fabricator.php:

<?php

// config for Z3d0X/FilamentFabricator
return [
    ...
    'table_name' => 'fabricator_pages',
];

The error on php artisan migrate:

SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'pages' (Connection: mysql, SQL: alter table `fabricator_pages` add constraint `fabricator_pages_parent_id_foreign` foreign key (`parent_id`) references `pages` (`id`) on delete cascade on update cascade)

Passing data to a specific layout

I was wondering how to pass data to a specific page layout.

Lets say i have a ProductResource and a layout Products.
I want to be able to collect all products and pass it to the product layout.

Like this:
return view('products', ['products' => $products]);

I don't know if this is already possible.

Deleted Block will make a page unrenderable

Hello @Z3d0X

First, I want to thank you again for such a beautiful implementation of blocks in Filament!

So now, I ran into a problem: I deleted a block after a given page was saved into the database.
I expected that the rendering mechanism ignored the JSON's non-existing blocks, but an exception was thrown.

Is this the desired behavior?

Below is a screenshot and the video link at the timestamp where it happened. It's in Portuguese, but without sound, you realize what happened. After undeleting the block files, it went back to normal

https://youtu.be/4PGkwDa3B4s?t=4643

image

How to add to multiple models?

Sorry Discussions are disabled so asking this question here instead.

I can't figure out how to add fabricator to my other models - is it fixed to only the provided Pages model?
I really want to use it on a number of different models - is this possible?

Cache issue

First of all, great plugin! Thanks for your work!

I noticed that queries in PageBlocks are fired every time you visit a page. Take for example this block:

public static function getBlockSchema(): Block
    {
        return Block::make('my-block')
            ->schema([
                Select::make('users')
                    ->options(User::pluck('name', 'id'))
            ]);
    }

    public static function mutateData(array $data): array
    {
        return array_merge($data, [
            'users' => Cache::remember('my_block_users', 60, function () use ($data) {
                return User::find($data['users']);
            }),
        ]);
    }

When visiting the page, the mutated data is cached but the query for theSelect (User::pluck('name', 'id')) field is still running every time.

Cheers, Martin

Undefined array key "type" when removing blocks from the page

hi
my stacktrace: https://flareapp.io/share/v5pba3lP

I use
filament v3.2.44
livewire/liveire v3.4.7
spatie/laravel-translatable v.6.6.2
z3d0x/filament-fabricator v2.1.1
filament/spatie-laravel-translatable-plugin v3.2.44

I was so happy when I connected everything and the translation worked. But after a while I found the problem.
Unfortunately, removing blocks from the page does not work

When I delete block and push save, I get error

Undefined array key "type"
Screenshot 2024-03-07 at 13 27 47

It block all artisan commands in docker

When I try to use it inside Docker and run Artisan commands, it always throws this exception:
`SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "pages" does not exist
LINE 1: select * from "pages"
^ (Connection: pgsql, SQL: select * from "pages")

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:822
818▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
819▕ );
820▕ }
821▕
➜ 822▕ throw new QueryException(
823▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
824▕ );
825▕ }
826▕ }

1 [internal]:0
Illuminate\Foundation\Application::Illuminate\Foundation{closure}(Object(Z3d0X\FilamentFabricator\FilamentFabricatorServiceProvider))
+12 vendor frames`
this error happened because of the codes inside bootingPackage()

How to add multiple page models

How to add multiple page models

I've worked out you can add blocks to any Model.

public static function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput:make('title'),
                Group::make()
                    ->schema([
                        PageBuilder::make('blocks')
                            ->label(__('filament-fabricator::page-resource.labels.blocks'))
                            ->blocks(FilamentFabricator::getPageBlocks()),
                    ])->columnSpan(2),
            ]);
    }

And add a json field called `blocks to your table.

$table->json('blocks')->nullable();

Seems to work fine, so..? 🤷‍♂️

Originally posted by @tobz-nz in #44 (comment)

PageResource fix deprecation

getLabel() is deprecated Use getModelLabel() instead.

https://github.com/Z3d0X/filament-fabricator/blob/2.x/src/Resources/PageResource.php#L182

getPluralLabel() is deprecated Use getPluralModelLabel() instead.

https://github.com/Z3d0X/filament-fabricator/blob/2.x/src/Resources/PageResource.php#L187

Expected Update:

    public static function getModelLabel(): string
    {
        return __('filament-fabricator::page-resource.labels.page');
    }

    public static function getPluralModelLabel(): string
    {
        return __('filament-fabricator::page-resource.labels.pages');
    }

Slug unique `integrity constraint violation`

Original PR #133

Problem:
The application threw an exception for a duplicate entry for the key pages.pages_slug_unique when attempting to insert a new page with the same slug as an existing page, but with a different parent.

Solution:
The unique index on the slug column has been removed, and a new compound unique index has been introduced on the combination of slug and parent_id columns. This allows the same slug to be used as long as it has a different parent, thus ensuring unique URLs for different page hierarchies while avoiding the integrity constraint violation.

Original PR was closed because it updated the existing migration file, this way would for new installations of this package. To solve this issue for existing applications using this package a new migration must be created, for the proposed solution

Builder Blocks are instantiated during registration

Problem

This getName() method is called during block registration

public static function getName(): string
{
return static::getBlockSchema()->getName();
}

$this->pageBlocks->put($pageBlock::getName(), $pageBlock);

Potential Solution

A potential viable solution might be to Explicitly set a name like in Layouts

protected static ?string $name;
public static function getName(): string
{
return static::$name;
}

make:page-block could auto to generate $name.

This would be a breaking a change, since existing application would need to explicitly set the $name.

Other ideas are welcome

Spatie\Translatable

Hello
when i try use Spatie\Translatable\HasTranslations

i add in model

use HasTranslations;

public array $translatable = [
    'title',
    'slug',
    'blocks',
];

i found error when i try to edit page also not save block in first time only save in edit

image

Creating Pages without slug

Hi,

It seems that creating a page without a slug is not possible? i would like to create a home page..

also how would you do a blog with single post page?

thanks for answers

Duplicates in cluster navigation

It duplicates in cluster navigation window and shows one in default navigation window.

Version: 2.0.5
Filament Version: 3.2.9

Screenshot 2024-01-22 at 11 25 11

[Documentation]: Schema Slots Feature

Note: this feature is implemented just need to be documented

If you add custom columns to Page Model you can use schema slots to add additional fields to the Page Resource Form, without overriding it.

Example:

use Z3d0X\FilamentFabricator\Facades\FilamentFabricator;

// in boot of a service provider
FilamentFabricator::registerSchemaSlot('sidebar.after', [
  TextInput::make('seo_title'),
  Textarea::make('seo_description'),
]);

Available Schema Slots:

  • blocks.before
  • blocks.after
  • sidebar.before
  • sidebar.before

Bug default routing config has few bugs

Default routing config is

    'routing' => [
        'enabled' => true,
        'prefix'  => null, //    /pages
    ],

With default values, you will receive 404 errors for non-filament routes with ModelNotFoundException for No query results for model [Z3d0X\FilamentFabricator\Models\Page].

1st workaround is to disable the routing but then you won't be able to use fabricator page routes.

2nd workaround is to use a prefix for the fabricator routing eg: pages.

However non-null prefix values cause another minor bug for the Visit action of Page resource.

Filament default route prefix is /admin and fabricator will send you to /admin/pages/xyz instead of /pagess/page-xyz when you click the Visit action of your fabricator page.

Session empty on Fabricator Pages

Hi,

i have noticed that the Sessions seems to be Empty or not Set when a User visits a Page from the Fabricator.
I have tested this with a fresh and clean Installation of Laravel, Filament and this Package.

@dump(auth())

in the Layout-File returns "null", even when a User is logged in

I am wondering if anyone else can confirm this

Thanks!

Layout "default" not found

Discussed in #101

Originally posted by devhoussam1998 October 14, 2023
Why I get Filament Fabricator: Layout "default" not found when I did not select any layout.

Screen.Recording.2023-10-14.at.00.58.17.mov
Screenshot 2023-10-14 at 01 00 04

as you can see above why the validation message does not show up for layout?

Localization Support

I use Fabricator with Spatie Translatable.
So slugs are stored like:
{"nl":"test-nl","de":"test-de"}

When the Dutch locale is set, the pageUrls are like this:
$pageUrls[1] = "/test-nl"

This is Cached with the key:
filament-fabricator::page-urls

When the German page is requested, the Dutch $pageUrls are returned so no page is found.

Layout not found when using artisan queue:work

Hi!

I'm encountering a strange issue, as the "php artisan queue:work" command always fails when adding a job to the default queue:

Exception: Filament Fabricator: Layout 'default' not found in file C:\xampp\htdocs\filament-test-export\vendor\z3d0x\filament-fabricator\src\Http\Controllers\PageController.php on line 31

The job is using spatie/laravel-export which crawls the urls of the website.
When using the commands "php artisan queue:work --once" and "php artisan queue:listen", everything is fine, but running "php artisan queue:work" will throw the exception above, although the layout has been created by running "php artisan filament-fabricator:layout DefaultLayout".

Do you have any clue of what can cause this error?

Thx!

Unable to install V2 of this package with Filament 3.x

Tried installing the package but I am getting a sub-dependency error about pboivin/filament-peek ^2.0

I am on Laravel ^10.10, Filament ^3.0-stable

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires z3d0x/filament-fabricator ^2.0 -> satisfiable by z3d0x/filament-fabricator[v2.0.0, v2.0.1].
    - z3d0x/filament-fabricator[v2.0.0, ..., v2.0.1] require pboivin/filament-peek ^2.0 -> found pboivin/filament-peek[v2.0.0-alpha1, ..., 2.x-dev] but it does not match your minimum-stability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.