1. Go to this page and download the library: Download phpsa/filament-headless-cms library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpsa / filament-headless-cms example snippets
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('/admin')
...
->plugin(FilamentHeadlessCms::make())
namespace App\Filament\PageTemplates;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Component;
use Phpsa\FilamentHeadlessCms\Contracts\PageTemplate;
use Phpsa\FilamentHeadlessCms\Filament\Fields\Editor;
class CustomPageTemplate extends PageTemplate
{
public static function title(): string
{
return 'Custom Page';
}
/**
* @return array<int|string, Component>
*/
public static function schema(): array
{
return [
Section::make()
->schema([
Editor::make('content')
->label('Content'),
])
];
}
}
//change default pagination
public static bool|array|Closure $paginate = true;
//should the items be sortable?
public static bool $sortable = false;
protected static int $sortOrder = 0; // set the order in nav
protected static bool $hasSeo = true; //no SEO, switch to false, why though?
protected static bool $publishDates = true; // if you do not need to publish on a date and it should just be... :-)
abstract public static function title(): string; //The value in here should be unique, it is the identifier for your template
abstract public static function schema(): array; // the actual form main body area, you can do whatever here, sections, tabs, wizards, builders etc.
public static function sidebarSchema(): array; //want to add another sidebar above the SEO?
//add area before and after the title area
public static function beforePrimaryColumnSchema(): array;
public static function afterPrimaryColumnSchema(): array;
// add area before and after the fields in the main sidebar
public static function beforeSecondaryColumnSchema(): array;
public static function afterSecondaryColumnSchema(): array;
// need to manipulate the data for your api response?
public static function toApiResponse(array $data): array
{
if (filled($data['featured_image'])) {
$data['featured_image'] = Storage::disk(config('filament.default_filesystem_disk'))->url($data['featured_image']);
}
return $data;
}
//Update this if using laravel scout to setup your searchable information
public function toSearchableArray(FilamentPage $record): array
{
return $this->apiTransform($record);
}
FilamentHeadlessCms::make()
->setResource(ResourceFile::class) // in case you want to customize it, you can extend the PageResource::class
->setModel(Model::class) // woudl recomend extending FhcmsContent - must implement FilamentPage
->setNavigation([
'group' => 'Content',
'icon' => 'heroicon-o-document',
'sort' => null,
'parent' => null,
'icon_active' => 'heroicon-s-document',
]);
->setSiteUrl('https://xxxx') //--> defaults to config('app.frontend_url') ?? config('app.url')
->setTemplates(array $templates, bool $flush = false) // add or completely replace templates
->setUploadFormField(FileUpload::class) // if using default templates or built in upload class -- make sure to use this file uploader
->setEditorFormField(Editor::class) // which rich / markdown form field editor to use - if using default templates
->setApiMiddleware(['api']) // defaults to ['api']
->setApiPrefix('api') // defaults to api
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.