PHP code example of cube-agency / filament-template
1. Go to this page and download the library: Download cube-agency/filament-template 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/ */
cube-agency / filament-template example snippets
$table->string('template');
php artisan filament-template:create Blog
return [
'templates' => [
\App\Filament\Templates\BlogTemplate::class,
]
];
class CreatePage extends CreateRecord
{
public $template;
protected $queryString = ['template'];
}
public static function form(Form $form): Form
{
return $form
->schema([
// ...
Hidden::make('template')
->default($this->getTemplate()),
Template::make('content')
->template($this->resolveTemplate()),
]);
}
protected function resolveTemplate()
{
return app($this->getTemplate());
}
protected function getTemplate()
{
if (property_exists($this, 'template')) {
return $this->template;
}
return $this->getRecord()->getAttribute('template');
}
public function getActions(): array
{
return [
Action::make('create')
->form($this->actionForm())
->action(function (array $data): void {
$parameters = http_build_query($data);
$this->redirect(static::$resource::getUrl('create') . '?' . $parameters);
})
];
}
protected function getTemplates(): Collection
{
return collect(config('filament-template.templates'))->mapWithKeys(function ($template) {
$templateName = explode('\\', $template);
return [$template => end($templateName)];
});
}
protected function actionForm(): array
{
return [
Select::make('template')
->label('Template')
->options($this->getTemplates())
->
bash
php artisan vendor:publish --tag="filament-template-config"