first commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tools\Pages;
|
||||
|
||||
use App\Filament\Resources\Tools\ToolResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateTool extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ToolResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tools\Pages;
|
||||
|
||||
use App\Filament\Resources\Tools\ToolResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditTool extends EditRecord
|
||||
{
|
||||
protected static string $resource = ToolResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tools\Pages;
|
||||
|
||||
use App\Filament\Resources\Tools\ToolResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTools extends ListRecords
|
||||
{
|
||||
protected static string $resource = ToolResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tools\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ToolsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
ImageColumn::make('logo_url')
|
||||
->label(''),
|
||||
TextColumn::make('name')
|
||||
->searchable()
|
||||
->weight('medium'),
|
||||
TextColumn::make('category')
|
||||
->formatStateUsing(fn (string $state) => config("tools.categories.{$state}", $state))
|
||||
->badge()
|
||||
->sortable(),
|
||||
TextColumn::make('subcategory')
|
||||
->placeholder('—'),
|
||||
TextColumn::make('pricing')
|
||||
->placeholder('—'),
|
||||
TextColumn::make('views')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('clicks')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
IconColumn::make('featured')
|
||||
->boolean()
|
||||
->sortable(),
|
||||
IconColumn::make('approved')
|
||||
->boolean()
|
||||
->sortable(),
|
||||
TextColumn::make('user.name')
|
||||
->label('Submitted by')
|
||||
->placeholder('—')
|
||||
->searchable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
SelectFilter::make('category')
|
||||
->options(config('tools.categories')),
|
||||
TernaryFilter::make('approved'),
|
||||
TernaryFilter::make('featured'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tools;
|
||||
|
||||
use App\Filament\Resources\Tools\Pages\CreateTool;
|
||||
use App\Filament\Resources\Tools\Pages\EditTool;
|
||||
use App\Filament\Resources\Tools\Pages\ListTools;
|
||||
use App\Filament\Resources\Tools\Schemas\ToolForm;
|
||||
use App\Filament\Resources\Tools\Tables\ToolsTable;
|
||||
use App\Models\Tool;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ToolResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Tool::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedWrenchScrewdriver;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Tools';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return ToolForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return ToolsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListTools::route('/'),
|
||||
'create' => CreateTool::route('/create'),
|
||||
'edit' => EditTool::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user