refactor: Remove FeedStatus enum and its references from FeedResource, Feed model, and migration
This commit is contained in:
parent
56038a3bf7
commit
244a548a4c
@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Enums;
|
|
||||||
|
|
||||||
use App\Traits\Enum\WithComment;
|
|
||||||
use App\Traits\Enum\WithValue;
|
|
||||||
use Filament\Support\Contracts\HasColor;
|
|
||||||
use Filament\Support\Contracts\HasLabel;
|
|
||||||
|
|
||||||
enum FeedStatus: int implements HasColor, HasLabel
|
|
||||||
{
|
|
||||||
use WithComment, WithValue;
|
|
||||||
|
|
||||||
case AVAILABLE = 1;
|
|
||||||
case OUT_OF_STOCK = 2;
|
|
||||||
case DISCONTINUED = 3;
|
|
||||||
|
|
||||||
public function getLabel(): ?string
|
|
||||||
{
|
|
||||||
return match ($this) {
|
|
||||||
self::AVAILABLE => 'Tersedia',
|
|
||||||
self::OUT_OF_STOCK => 'Habis',
|
|
||||||
self::DISCONTINUED => 'Tidak Digunakan',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getColor(): string|array|null
|
|
||||||
{
|
|
||||||
return match ($this) {
|
|
||||||
self::AVAILABLE => 'success',
|
|
||||||
self::OUT_OF_STOCK => 'danger',
|
|
||||||
self::DISCONTINUED => 'gray',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function options(): array
|
|
||||||
{
|
|
||||||
return collect(self::cases())
|
|
||||||
->mapWithKeys(fn ($case) => [$case->value => $case->getLabel()])
|
|
||||||
->toArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Master\Feeds;
|
namespace App\Filament\Resources\Master\Feeds;
|
||||||
|
|
||||||
use App\Enums\FeedStatus;
|
|
||||||
use App\Filament\Actions\Cheerful\DeleteAction;
|
use App\Filament\Actions\Cheerful\DeleteAction;
|
||||||
use App\Filament\Actions\Cheerful\EditAction;
|
use App\Filament\Actions\Cheerful\EditAction;
|
||||||
use App\Filament\Actions\Cheerful\ForceDeleteAction;
|
use App\Filament\Actions\Cheerful\ForceDeleteAction;
|
||||||
@ -22,7 +21,6 @@
|
|||||||
use Filament\Support\Icons\Heroicon;
|
use Filament\Support\Icons\Heroicon;
|
||||||
use Filament\Support\RawJs;
|
use Filament\Support\RawJs;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
use Filament\Tables\Filters\SelectFilter;
|
|
||||||
use Filament\Tables\Filters\TrashedFilter;
|
use Filament\Tables\Filters\TrashedFilter;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@ -65,13 +63,6 @@ public static function form(Schema $schema): Schema
|
|||||||
->searchable()
|
->searchable()
|
||||||
->preload(),
|
->preload(),
|
||||||
|
|
||||||
Select::make('status')
|
|
||||||
->label('Status')
|
|
||||||
->options(FeedStatus::class)
|
|
||||||
->required()
|
|
||||||
->native(false)
|
|
||||||
->default(FeedStatus::AVAILABLE),
|
|
||||||
|
|
||||||
TextInput::make('price')
|
TextInput::make('price')
|
||||||
->label('Harga')
|
->label('Harga')
|
||||||
->placeholder('1,000,000')
|
->placeholder('1,000,000')
|
||||||
@ -118,19 +109,9 @@ public static function table(Table $table): Table
|
|||||||
->label('Harga')
|
->label('Harga')
|
||||||
->money('IDR', decimalPlaces: 0),
|
->money('IDR', decimalPlaces: 0),
|
||||||
|
|
||||||
TextColumn::make('status')
|
|
||||||
->label('Status')
|
|
||||||
->badge()
|
|
||||||
->sortable(),
|
|
||||||
|
|
||||||
...TimestampColumns::make(),
|
...TimestampColumns::make(),
|
||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
SelectFilter::make('status')
|
|
||||||
->label('Status')
|
|
||||||
->options(FeedStatus::class)
|
|
||||||
->native(false),
|
|
||||||
|
|
||||||
TrashedFilter::make()
|
TrashedFilter::make()
|
||||||
->native(false),
|
->native(false),
|
||||||
])
|
])
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Enums\FeedStatus;
|
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@ -22,7 +21,6 @@ protected function casts(): array
|
|||||||
return [
|
return [
|
||||||
'stock' => 'decimal:2',
|
'stock' => 'decimal:2',
|
||||||
'price' => 'integer',
|
'price' => 'integer',
|
||||||
'status' => FeedStatus::class,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Enums\FeedStatus;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -18,7 +17,6 @@ public function up(): void
|
|||||||
$table->foreignId('unit_id')->constrained()->cascadeOnDelete();
|
$table->foreignId('unit_id')->constrained()->cascadeOnDelete();
|
||||||
$table->decimal('stock', 15, 2)->default(0);
|
$table->decimal('stock', 15, 2)->default(0);
|
||||||
$table->unsignedInteger('price');
|
$table->unsignedInteger('price');
|
||||||
$table->enum('status', FeedStatus::cases())->default(FeedStatus::AVAILABLE->value)->comment(FeedStatus::comment());
|
|
||||||
$table->timestamp('created_at')->useCurrent();
|
$table->timestamp('created_at')->useCurrent();
|
||||||
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||||
$table->softDeletes();
|
$table->softDeletes();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user