Add Destination resource (T2.2)
Migration/model/factory for destinations (name, mm_name, region, description fields, geo coordinates, is_active, popular) plus its Filament resource.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Catalog\Filament\Resources\Destinations;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Modules\Catalog\Filament\Resources\Destinations\Pages\CreateDestination;
|
||||
use Modules\Catalog\Filament\Resources\Destinations\Pages\EditDestination;
|
||||
use Modules\Catalog\Filament\Resources\Destinations\Pages\ListDestinations;
|
||||
use Modules\Catalog\Filament\Resources\Destinations\Schemas\DestinationForm;
|
||||
use Modules\Catalog\Filament\Resources\Destinations\Tables\DestinationsTable;
|
||||
use Modules\Catalog\Models\Destination;
|
||||
use UnitEnum;
|
||||
|
||||
class DestinationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Destination::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Catalog';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return DestinationForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return DestinationsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListDestinations::route('/'),
|
||||
'create' => CreateDestination::route('/create'),
|
||||
'edit' => EditDestination::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Catalog\Filament\Resources\Destinations\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Modules\Catalog\Filament\Resources\Destinations\DestinationResource;
|
||||
|
||||
class CreateDestination extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DestinationResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Catalog\Filament\Resources\Destinations\Pages;
|
||||
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Modules\Catalog\Filament\Resources\Destinations\DestinationResource;
|
||||
|
||||
class EditDestination extends EditRecord
|
||||
{
|
||||
protected static string $resource = DestinationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Catalog\Filament\Resources\Destinations\Pages;
|
||||
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Modules\Catalog\Filament\Resources\Destinations\DestinationResource;
|
||||
|
||||
class ListDestinations extends ListRecords
|
||||
{
|
||||
protected static string $resource = DestinationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Catalog\Filament\Resources\Destinations\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class DestinationForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('mm_name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('region')
|
||||
->maxLength(255),
|
||||
Textarea::make('description')
|
||||
->columnSpanFull(),
|
||||
Textarea::make('mm_description')
|
||||
->columnSpanFull(),
|
||||
Textarea::make('meta_keyword')
|
||||
->columnSpanFull(),
|
||||
Textarea::make('meta_description')
|
||||
->columnSpanFull(),
|
||||
TextInput::make('latitude')
|
||||
->maxLength(255),
|
||||
TextInput::make('longitude')
|
||||
->maxLength(255),
|
||||
Toggle::make('is_active')
|
||||
->required()
|
||||
->default(true),
|
||||
Toggle::make('popular')
|
||||
->required()
|
||||
->default(false),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Catalog\Filament\Resources\Destinations\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class DestinationsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('region')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
IconColumn::make('is_active')
|
||||
->boolean(),
|
||||
IconColumn::make('popular')
|
||||
->boolean(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
TernaryFilter::make('is_active'),
|
||||
TernaryFilter::make('popular'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Catalog\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Modules\Catalog\Database\Factories\DestinationFactory;
|
||||
|
||||
class Destination extends Model
|
||||
{
|
||||
/** @use HasFactory<DestinationFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'mm_name',
|
||||
'region',
|
||||
'description',
|
||||
'mm_description',
|
||||
'meta_keyword',
|
||||
'meta_description',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'is_active',
|
||||
'popular',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
'popular' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user