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.
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"
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.
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>
There is a FlatPageTest.php file where you can run to check if tests are passing
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
Give a ⭐️ if you like this project or find it helpful!
The MIT License (MIT). Please see License File for more information.
A full-stack Software Engineer from Cyprus.
I am an experienced Software Developer with a strong background in the internet industry, working since 2012. My skills include PHP, Go programming language, relational database systems, and JavaScript frameworks such as React, Svelte, and Angular. I hold a computer science degree from the Technological Educational Institute of Western Macedonia.