97 lines
2.9 KiB
PHP
97 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\PromoResource\Pages;
|
|
use App\Filament\Resources\PromoResource\RelationManagers;
|
|
use App\Models\Promo;
|
|
use Filament\Forms\Components\Grid;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\Group;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Forms\Form;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Forms\Components\Section;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Tables\Columns\BadgeColumn;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use League\Uri\Idna\Option;
|
|
|
|
class PromoResource extends Resource
|
|
{
|
|
protected static ?string $model = Promo::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-currency-dollar';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Section::make([
|
|
Group::make()
|
|
->schema([
|
|
TextInput::make('kode')
|
|
->label('Kode Promo'),
|
|
Select::make('tipe')
|
|
->label('Tipe Promo')
|
|
->options(['fix'=>'Fix','persen'=>'Persentase']),
|
|
TextInput::make('diskon'),
|
|
]),
|
|
Toggle::make('aktif')
|
|
->default(true),
|
|
])
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('kode')
|
|
->label('Kode Promo'),
|
|
TextColumn::make('tipe')
|
|
->label('Tipe Promo'),
|
|
TextColumn::make('diskon'),
|
|
BadgeColumn::make('aktif')
|
|
->label('Status')
|
|
->formatStateUsing(fn ($state) => $state ? 'Aktif' : 'Nonaktif')
|
|
->colors([
|
|
'success' => fn ($state): bool => $state, // Warna hijau jika aktif
|
|
'danger' => fn ($state): bool => !$state // Warna merah jika nonaktif
|
|
])
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListPromos::route('/'),
|
|
'create' => Pages\CreatePromo::route('/create'),
|
|
'edit' => Pages\EditPromo::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|