first commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tools\Schemas;
|
||||
|
||||
use App\Models\Tool;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TagsInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ToolForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(3)
|
||||
->components([
|
||||
Section::make('Details')
|
||||
->columnSpan(2)
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(function (string $operation, $state, callable $set) {
|
||||
if ($operation === 'create') {
|
||||
$set('slug', Str::slug($state));
|
||||
}
|
||||
}),
|
||||
TextInput::make('slug')
|
||||
->required()
|
||||
->unique(Tool::class, 'slug', ignoreRecord: true)
|
||||
->helperText('Used in the URL, e.g. /tools/your-slug'),
|
||||
Textarea::make('description')
|
||||
->required()
|
||||
->rows(4)
|
||||
->columnSpanFull(),
|
||||
TextInput::make('url')
|
||||
->label('Website URL')
|
||||
->url()
|
||||
->required(),
|
||||
TextInput::make('logo_url')
|
||||
->label('Logo URL')
|
||||
->url(),
|
||||
TagsInput::make('tags')
|
||||
->placeholder('Add a tag and press enter')
|
||||
->helperText('e.g. free, api, open-source')
|
||||
->columnSpanFull(),
|
||||
TagsInput::make('features')
|
||||
->placeholder('Add a feature and press enter')
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Section::make('Classification')
|
||||
->columnSpan(1)
|
||||
->components([
|
||||
Select::make('category')
|
||||
->options(config('tools.categories'))
|
||||
->required()
|
||||
->searchable(),
|
||||
TextInput::make('subcategory')
|
||||
->helperText('e.g. Code Assistants'),
|
||||
TextInput::make('pricing')
|
||||
->helperText('e.g. Free, Freemium, $10/month'),
|
||||
]),
|
||||
Section::make('Moderation')
|
||||
->columnSpan(3)
|
||||
->columns(4)
|
||||
->components([
|
||||
Toggle::make('approved')
|
||||
->helperText('Only approved tools are shown publicly.')
|
||||
->default(false),
|
||||
Toggle::make('featured')
|
||||
->helperText('Highlight this tool.')
|
||||
->default(false),
|
||||
Select::make('user_id')
|
||||
->label('Submitted by')
|
||||
->relationship('user', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
TextInput::make('views')
|
||||
->numeric()
|
||||
->default(0)
|
||||
->disabled()
|
||||
->dehydrated(),
|
||||
TextInput::make('clicks')
|
||||
->numeric()
|
||||
->default(0)
|
||||
->disabled()
|
||||
->dehydrated(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user