GithubHelp home page GithubHelp logo

pascalebeier / filament-pages Goto Github PK

View Code? Open in Web Editor NEW
47.0 5.0 8.0 857 KB

A starting point to create a Page Resource and front routing with filament. It is the result of packaging our Page CMS functionality.

License: MIT License

PHP 98.07% JavaScript 1.93%
filament laravel pages

filament-pages's Introduction

Screenshot

beier/filament-pages

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A starting point to create a Page Resource and front routing with filament. It is the result of packaging our Page CMS functionality.

This package does not register any routes, as page routing always depends on your project. This is meant to be providing you a quickstart in creating a dynamic page module.

Demo

Demo

Screenshots

Screenshot of list view Screenshot of resource view

Installation

You can install the package via composer:

composer require beier/filament-pages

You can run the installation command with:

php artisan filament-pages:install

This is the contents of the published config file:

<?php

use Beier\FilamentPages\Filament\FilamentPageTemplates\DefaultTemplate;
use Beier\FilamentPages\Filament\Resources\FilamentPageResource;
use Beier\FilamentPages\Models\FilamentPage;
use Beier\FilamentPages\Renderer\SimplePageRenderer;

return [
    'filament' => [
        /*
        |--------------------------------------------------------------------------
        | Filament: Custom Filament Resource
        |--------------------------------------------------------------------------
        |
        | Use your own extension of the FilamentPageResource
        | below to fully customize every aspect of it.
        |
        */
        'resource' => FilamentPageResource::class,
        /*
        |--------------------------------------------------------------------------
        | Filament: Custom Filament Model
        |--------------------------------------------------------------------------
        |
        | Use your own extension of the FilamentPage Model
        | below to fully customize every aspect of it.
        |
        */
        'model' => FilamentPage::class,
        /*
        |--------------------------------------------------------------------------
        | Filament: Title Attribute
        |--------------------------------------------------------------------------
        |
        | Point to another field or Attribute to change the
        | computed record title provided in filament.
        |
        */
        'recordTitleAttribute' => 'title',
        /*
        |--------------------------------------------------------------------------
        | Filament: Label
        |--------------------------------------------------------------------------
        |
        | If you don't need to support multiple languages you can
        | globally change the model label below. If you do,
        | you should rather change the translation files.
        |
        */
        'modelLabel' => 'Page',
        /*
        |--------------------------------------------------------------------------
        | Filament: Plural Label
        |--------------------------------------------------------------------------
        |
        | If you don't need to support multiple languages you can
        | globally change the plural label below. If you do,
        | you should rather change the translation files.
        |
        */
        'pluralLabel' => 'Pages',
        'navigation' => [
            /*
            |--------------------------------------------------------------------------
            | Filament: Navigation Icon
            |--------------------------------------------------------------------------
            |
            | If you don't need to support multiple languages you can
            | globally change the navigation icon below. If you do,
            | you should rather change the translation files.
            |
            */
            'icon' => 'heroicon-o-document',
            /*
            |--------------------------------------------------------------------------
            | Filament: Navigation Group
            |--------------------------------------------------------------------------
            |
            | If you don't need to support multiple languages you can
            | globally change the navigation group below. If you do,
            | you should rather change the translation files.
            |
            */
            'group' => 'content',
            /*
            |--------------------------------------------------------------------------
            | Filament: Navigation Group
            |--------------------------------------------------------------------------
            |
            | If you don't need to support multiple languages you can
            | globally change the navigation sort below. If you do,
            | you should rather change the translation files.
            |
            */
            'sort' => null,
        ]
    ],
    /*
    |--------------------------------------------------------------------------
    | Templates
    |--------------------------------------------------------------------------
    |
    | Add your own Templates implementing FilamentPageTemplate::class
    | below. They will appear in the Template selection,
    | and persisted to the data column.
    |
    */
    'templates' => [
        DefaultTemplate::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Renderer
    |--------------------------------------------------------------------------
    |
    | If you want to use the Rendering functionality, you can create your 
    | own Renderer here. Take the available Renderers for reference.
    | See FilamentPageController for recommended usage.
    | 
    | Available Renderers:
    | - SimplePageRenderer: 
    |   Renders everything to the defined layout below.
    | - AtomicDesignPageRenderer: 
    |   More opinionated Renderer to be used with Atomic Design.
    |
    | To use the renderer, Add a Route for the exemplary FilamentPageController:
    | 
    |  Route::get('/{filamentPage}', [FilamentPageController::class, 'show']);
    |
    | To route the homepage, you could add a data.is_homepage 
    | field and query it in a controller.
    | 
    */
    'renderer' => SimplePageRenderer::class,

    /*
    |--------------------------------------------------------------------------
    | Simple Page Renderer: Default Layout
    |--------------------------------------------------------------------------
    |
    | Only applicable to the SimplePageRenderer.
    | 
    */
    'default_layout' => 'layouts.app',
];

Usage

Within Filament

After running the Install Command, you will find a new Page Resource in your Filament Admin.

Templates

This package uses the concept of Template-based forms by Dennis Koch (pxlrbt). You can read more about the general idea in his Filament Trick.

You will find a basic page template. By creating and selecting your own templates, you are able to fully customize your pages.

To create your own Templates, implement the Beier\FilamentPages\Contracts\FilamentPageTemplate:

<?php

namespace App\Filament\FilamentPageTemplates;

use Beier\FilamentPages\Contracts\FilamentPageTemplate;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\RichEditor;

class MyTemplate implements FilamentPageTemplate
{
    public static function title(): string
    {
        return 'My Template';
    }

    public static function schema(): array
    {
        return [
            Card::make()
                ->schema([
                    RichEditor::make('content')
                ]),
        ];
    }
}

Finally, register your template in config/filament-pages.php:

<?php

return [
    'templates' => [
        // \Beier\FilamentPages\Filament\FilamentPageTemplates\DefaultTemplate::class,
        \App\Filament\FilamentPageTemplates\MyTemplate::class,
    ],
];

Your template will appear in the Template Selection and render your schema accordingly.

Customizing the Page Resource

The recommended way of extending the Page Resource is overriding

  • FilamentPageResource::insertBeforePrimaryColumnSchema
  • FilamentPageResource::insertAfterPrimaryColumnSchema
  • FilamentPageResource::insertBeforeSecondaryColumnSchema
  • FilamentPageResource::insertAfterSecondaryColumnSchema

in your own PageResource class, extending Beier\FilamentPages\Filament\Resources\FilamentPageResource.

You will find most common configuration options in the config file.

<?php

namespace App\Filament\Resources;

use Beier\FilamentPages\Filament\Resources\FilamentPageResource;
use Filament\Resources\Form;
use Filament\Resources\Table;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Components\TextInput;

class PageResource extends FilamentPageResource
{
    /**
     * Recommended: Insert Fields at the beginning of the primary column.
     */
    public static function insertBeforePrimaryColumnSchema(): array
    {

        return [
            Toggle::make('is_homepage'),
        ];
    }
    
    /**
     * Recommended: Insert Fields at the end of the primary column.
     */
    public static function insertAfterPrimaryColumnSchema(): array
    {

        return [
            TextInput::make('author'),
        ];
    }
    
    /**
     * Recommended: Insert Fields at the beginning of the secondary column. (sidebar)
     */
    public static function insertBeforeSecondaryColumnSchema(): array
    {

        return [
            Toggle::make('is_homepage'),
        ];
    }
    
    /**
     * Recommended: Insert Fields at the end of the secondary column. (sidebar)
     */
    public static function insertAfterSecondaryColumnSchema(): array
    {

        return [
            SEO::make(),
        ];
    }

    /**
     * Not Recommended: Override the whole form
     */
   /** public static function form(Form $form): Form
    {

        return $form
            ->schema([
                //
            ]);
    } */
    
    /**
     * Not Recommended: Override the whole table
     */
    /** public static function table(Table $table): Table
    {

        return $table
            ->columns([
                //
            ]);
    } */
}

Then, register your class within config/filament-pages.php

<?php

use App\Filament\Resources\PageResource;

return [
    'filament' => [
        'resource' => PageResource::class,
    ],
]

Examples

  1. Create app/Models/FilamentPage.php

    <?php
    
    namespace App\Models;
    
    use Beier\FilamentPages\Models\FilamentPage as BeierFilamentPage;
    use RalphJSmit\Laravel\SEO\Support\HasSEO;
    use RalphJSmit\Laravel\SEO\Support\SEOData;
    
    class FilamentPage extends BeierFilamentPage
    {
        use HasSEO;
    
        public function getDynamicSEOData(): SEOData
        {
            return new SEOData(
                title: $this->title,
            );
        }
    
    }
  2. Create app/Filament/Resources/PageResource.php

    <?php
    
    namespace App\Filament\Resources;
    
    use RalphJSmit\Filament\SEO\SEO;
    use Beier\FilamentPages\Filament\Resources\FilamentPageResource;
    
    class PageResource extends FilamentPageResource
    {
        public static function insertAfterSecondaryColumnSchema(): array
        {
            return [
                SEO::make(),
            ];
        }
    }
  3. Define Model and Resource in config/filament-pages.php

    return [
        'filament' => [
             'resource' => \App\Filament\Resources\PageResource::class,
             'model' => \App\Models\FilamentPage::class,
        ],
    ];
  4. If necessary, clear application caches for the Service Locator to load your resource:

    $ php artisan cache:clear

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

filament-pages's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar pascalebeier 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

Watchers

 avatar  avatar  avatar  avatar  avatar

filament-pages's Issues

Support Filament v3

Discussed in #15

Originally posted by scryba March 6, 2024
Could you please make it compatible with filament v3?

Fields from other template on content array

Hi,

I have 2 templates, one is the home page and the other is a section template. When I save my second page, all the data from the home page is kept in the "data" column in DB, with a null value.

This is my homePage values :

{
  "content": {
    "title": "Les dernières boutiques",
    "content": "Lorem ipsum dolor sit amet consectetur. Risus est eu hendrerit nulla in ac cursus at. Porttitor non arcu platea sagittis imperdiet arcu sed. Arcu vel scelerisque quam sed consectetur elementum. Molestie mi mauris mattis in ultricies dignissim.",
    "categories": [
      "26",
      "51",
      "74",
      "124",
      "99",
      "135",
      "148",
      "1"
    ],
    "categories_title": "Les dernières catégories",
    "categories_content": "Lorem ipsum dolor sit amet consectetur. Risus est eu hendrerit nulla in ac cursus at. Porttitor non arcu platea sagittis imperdiet arcu sed. Arcu vel scelerisque quam sed consectetur elementum. Molestie mi mauris mattis in ultricies dignissim.",
    "shops_title": "Les dernières boutiques",
    "shops_content": "Lorem ipsum dolor sit amet consectetur. Risus est eu hendrerit nulla in ac cursus at. Porttitor non arcu platea sagittis imperdiet arcu sed. Arcu vel scelerisque quam sed consectetur elementum. Molestie mi mauris mattis in ultricies dignissim.",
    "image": {
      "0bcd37fd-a8f6-4fce-8ae6-1f260d4756cc": "images/home-intro-MIwPlmVacg.jpg"
    },
    "products_title": "Les dernières nouveautés",
    "intro_title": "Perpignan.com, c’est quoi ?",
    "intro_subtitle": "Lorem ipsum dolor sit amet consectetur.",
    "intro_content": "Lorem ipsum dolor sit amet consectetur. Tellus euismod vitae mi massa velit urna aenean donec. Risus et morbi egestas posuere dictum consequat sollicitudin. Pellentesque elementum pharetra dictum feugiat fermentum. Facilisis nisl et tortor gravida. In vulputate elementum et enim sed egestas vel. Eleifend praesent nisi vitae eu in. Ultrices nunc tristique lorem et pulvinar dui tincidunt venenatis ornare. Porttitor leo fringilla iaculis purus diam. Tempus mi imperdiet ipsum volutpat condimentum viverra senectus sed in. Tortor augue dignissim nunc eu. Tellus amet lorem turpis sed leo at cursus enim.\n\nGravida mattis posuere mollis elementum convallis quam maecenas. Dapibus et egestas massa scelerisque lectus habitasse est non adipiscing. Dapibus nulla semper enim in dignissim viverra adipiscing.",
    "offers_title": "Nos différentes offres",
    "offers_content": "Lorem ipsum dolor sit amet consectetur. Euismod vivamus adipiscing elit mauris diam enim vestibulum iaculis libero. At mauris in quisque ut viverra nibh a. Tristique ipsum sed faucibus vulputate arcu imperdiet. Massa morbi in ac et mattis. At eget interdum vel elementum ac tincidunt amet nisl mauris.",
    "faq_title": "Notre foire aux questions",
    "faq_subtitle": "Lorem ipsum dolor sit amet consectetur.",
    "faq_content": "Lorem ipsum dolor sit amet consectetur. Imperdiet sollicitudin metus donec cras urna. Sit quam ullamcorper gravida massa proin tellus. Velit amet facilisis amet at. Volutpat amet nunc nisl felis risus vitae consequat. Pulvinar molestie nisi non lorem eros orci tincidunt risus. Nullam amet.",
    "faq_questions": [
      {
        "question": "Question de Test",
        "response": "Réponse de Test"
      },
      {
        "question": "Question de Test 2",
        "response": "Réponse de test 2"
      }
    ],
    "intro_image": "images/home-intro-acEHnKqxtt.jpg",
    "h1": null,
    "subtitle": null,
    "component": null
  },
  "template": "App\\Filament\\Templates\\HomePage",
  "templateName": "home_page"
}

And this is my page section :

{
  "content": {
    "image": "9nqdSEQTkLNWVtajEQkWM85yTM0wr2-metaYmFubmVyLmpwZw==-.jpg",
    "h1": "Toutes nos boutiques",
    "content": null,
    "subtitle": "en un clic",
    "component": "shop-lists",
    "categories": [],
    "intro_image": [],
    "faq_questions": [],
    "categories_title": null,
    "categories_content": null,
    "shops_title": null,
    "shops_content": null,
    "products_title": null,
    "intro_title": null,
    "intro_subtitle": null,
    "intro_content": null,
    "offers_title": null,
    "offers_content": null,
    "faq_title": null,
    "faq_subtitle": null,
    "faq_content": null
  },
  "template": "App\\Filament\\Templates\\SectionPage",
  "templateName": "section_page"
}

We can see that all the fields of the home page have been kept.

Thanks for help,

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.