panakour / filament-flat-page
This is my package filament-flat-page
Fund package maintenance!
panakour
Requires
- php: ^8.2
- filament/filament: ^3.0
- spatie/laravel-package-tools: ^1.15.0
- spatie/valuestore: ^1.3
Requires (Dev)
- larastan/larastan: ^2.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9|^8.0
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^3.2
- pestphp/pest-plugin-arch: ^v3.0.0
- pestphp/pest-plugin-laravel: ^v3.0.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
README
FilamentFlatPage is a plugin for Filament that allows you to easily create and manage flat file pages with support for translations. It provides a simple way to add configurable, translatable pages to your Filament admin panel without the need for a database.
Features
- Easily create flat file pages with customizable forms
- Requires no database; data is stored in JSON files
- Built-in multilingual support for creating translatable content
- Seamless integration with Filament admin panel
- Language switcher in the admin page header (integrates with Spatie Translatable, if available)
Installation
You can install the package via composer:
composer require panakour/filament-flat-page
Optionally, you can publish the config file with:
php artisan vendor:publish --tag="filament-flat-page-config"
This will create a config/filament-flat-page.php
file where you can set your preferred options:
return [ 'locales' => ['en', 'fr', 'el'], ];
Optionally, you can publish the views using
php artisan vendor:publish --tag="filament-flat-page-views"
Usage
- Create a new page that extends
FlatPage
:
<?php namespace App\Filament\Pages; use Filament\Forms\Components\Section; use Filament\Forms\Components\Tabs; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Panakour\FilamentFlatPage\Pages\FlatPage; class Settings extends FlatPage { protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth'; protected static ?string $navigationGroup = 'Settings'; protected static ?string $title = 'Settings'; public function getSubheading(): ?string { return __('Manage your website settings'); } public function getFileName(): string { return 'settings.json'; } protected function getTranslatableFields(): array { return ['site_name', 'site_description', 'contact_address', 'contact_form_title', 'contact_form_content']; } protected function getFlatFilePageForm(): array { return [ Tabs::make('Settings') ->tabs([ Tabs\Tab::make('General') ->icon('heroicon-o-computer-desktop') ->schema([ Section::make('App Settings') ->icon('heroicon-o-computer-desktop') ->schema([ TextInput::make('site_name') ->required() ->hint('Translatable field.') ->hintIcon('heroicon-o-language') ->label('Site Name'), Textarea::make('site_description') ->hint('Translatable field.') ->hintIcon('heroicon-o-language') ->label('Site Description') ->rows(3), ]), ]), Tabs\Tab::make('Contact') ->icon('heroicon-o-envelope') ->schema([ Section::make('Contact Information') ->icon('heroicon-o-envelope') ->schema([ TextInput::make('contact_email') ->email() ->required() ->label('Contact Email'), TextInput::make('contact_phone') ->tel() ->label('Contact Phone'), Textarea::make('contact_address') ->hint('Translatable field.') ->hintIcon('heroicon-o-language') ->label('Address') ->rows(3), ]), Section::make('Contact Form') ->schema([ TextInput::make('contact_form_title') ->hint('Translatable field.') ->hintIcon('heroicon-o-language') ->label('Contact Form Title'), Textarea::make('contact_form_content') ->hint('Translatable field.') ->hintIcon('heroicon-o-language') ->label('Contact Form Content') ->rows(3), ]), ]), Tabs\Tab::make('Social Networks') ->icon('heroicon-o-heart') ->schema([ Section::make('Social Media Links') ->icon('heroicon-o-heart') ->schema([ TextInput::make('facebook') ->url() ->label('Facebook URL'), TextInput::make('twitter') ->url() ->label('Twitter URL'), TextInput::make('instagram') ->url() ->label('Instagram URL'), TextInput::make('linkedin') ->url() ->label('LinkedIn URL'), ]), ]), ]) ->columnSpan('full'), ]; } }
-
Define your form schema in the
getFlatFilePageForm()
method. -
Specify the translatable fields in the
getTranslatableFields()
method. -
Set the filename for storing the flat file data in the
getFileName()
method.
Using the FlatPage Facade
You can easily access your flat file data from anywhere in your application using the FlatPage
facade:
use \Panakour\FilamentFlatPage\Facades\FilamentFlatPage; // Get a non-translatable field $contactEmail = FilamentFlatPage::get('settings.json', 'contact_email'); // Get a translatable field (uses current locale) $siteName = FilamentFlatPage::get('settings.json', 'site_name'); // Get a translatable field in a specific locale $siteNameGreek = FilamentFlatPage::get('settings.json', 'site_name', 'el'); // Get all $allSettings = FilamentFlatPage::all('settings.json');
In Blade templates, you can use it like this:
<h1>{{ \Panakour\FilamentFlatPage\Facades\FilamentFlatPage::get("page.json", "title") }}</h1> <p>Contact Email: {{ Panakour\FilamentFlatPage\Facades\FilamentFlatPage::get('settings.json', 'contact_email') }}</p> <p>Site Name: {{ Panakour\FilamentFlatPage\Facades\FilamentFlatPage::get('settings.json', 'site_name', 'en') }}</p>
Testing
There is a FlatPageTest.php file where you can run to check if tests are passing
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
Show your support
Give a ⭐️ if you like this project or find it helpful!
License
The MIT License (MIT). Please see License File for more information.