This package is a simple plugin to allow required fields on forms to be draftable. Filament field components already could do it on demand using:
->nullable(true|false)
You can install the package via composer:
composer require ronssij/filament-simple-draft
You can publish the config file with:
php artisan vendor:publish --tag="filament-simple-draft-config"
This is the contents of the published config file:
// config/filament-simple-draft.php
return [
'publishable_column' => 'published_at',
];
On your model, these classes should be used. Make sure all of you draftable fields are nullable columns on your model.
use Ronssij\FilamentSimpleDraft\Contracts\CanBePublished;
use Ronssij\FilamentSimpleDraft\Publishable;
class User extends Authenticatable implements CanBePublished
{
// Optionally, you can set you published column identifier
// Or you can set it via configuration (config/filament-simple-draft.php).
protected ?string $publishColumn = 'published_date';
use Publishable;
}
On your Resources for CreateRecord and EditRecord:
use Filament\Resources\Pages\EditRecord;
use Ronssij\FilamentSimpleDraft\Pages\Traits\Edit\Draftable;
class EditUser extends EditRecord
{
use Draftable;
}
use Filament\Resources\Pages\CreateRecord;
use Ronssij\FilamentSimpleDraft\Pages\Traits\Create\Draftable;
class CreateUser extends CreateRecord
{
use Draftable;
}
Resource form usage:
By chaining ->draftable()
on any form fields it will be required when Published and nullable on Save Draft.
use Filament\Forms;
use Filament\Forms\Form;
use FilamentTiptapEditor\Enums\TiptapOutput;
use FilamentTiptapEditor\TiptapEditor;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('title')
->label('Blog title')
->draftable()
Forms\Components\Textarea::make('description')
->label('Blog description')
->rows(5)
->draftable()
TiptapEditor::make('content')
->label('Blog content')
->draftable()
->output(TiptapOutput::Html)
]);
}
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.
The MIT License (MIT). Please see License File for more information.