add carts
This commit is contained in:
116
app/Filament/Clusters/Cards/Cards/CardResource.php
Normal file
116
app/Filament/Clusters/Cards/Cards/CardResource.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\Cards\Cards;
|
||||
|
||||
use App\Filament\Clusters\Cards\Cards\Pages\ManageCards;
|
||||
use App\Filament\Clusters\Cards\CardsCluster;
|
||||
use App\Modules\AppHelpers\Repositories\DateHelper;
|
||||
use App\Modules\Card\Models\Card;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CardResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Card::class;
|
||||
|
||||
protected static ?string $cluster = CardsCluster::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCreditCard;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(3)
|
||||
->components([
|
||||
Hidden::make('user_id')
|
||||
->default(fn () => user()->id),
|
||||
|
||||
TextInput::make('number')
|
||||
->label(__('Card number'))
|
||||
->mask('9999 9999 9999 9999')
|
||||
->columnSpan('1')
|
||||
->required(),
|
||||
|
||||
Select::make('month')
|
||||
->label(__('Card month'))
|
||||
->options(DateHelper::staticNumberMonths())
|
||||
->native(false)
|
||||
->columnSpan('1')
|
||||
->required(),
|
||||
|
||||
Select::make('year')
|
||||
->label(__('Card year'))
|
||||
->options(DateHelper::staticNumberYears())
|
||||
->native(false)
|
||||
->columnSpan('1')
|
||||
->required(),
|
||||
|
||||
TextInput::make('name')
|
||||
->label(__('Card name'))
|
||||
->maxLength(255)
|
||||
->columnSpanFull()
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('number')
|
||||
->label(__('Card number'))
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('name')
|
||||
->label(__('Card name'))
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('month')
|
||||
->label(__('Card month'))
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('year')
|
||||
->label(__('Card year'))
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ManageCards::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Clusters/Cards/Cards/Pages/ManageCards.php
Normal file
19
app/Filament/Clusters/Cards/Cards/Pages/ManageCards.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\Cards\Cards\Pages;
|
||||
|
||||
use App\Filament\Clusters\Cards\Cards\CardResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageCards extends ManageRecords
|
||||
{
|
||||
protected static string $resource = CardResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ class CardsCluster extends Cluster
|
||||
{
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCreditCard;
|
||||
|
||||
protected static ?SubNavigationPosition $subNavigationPosition = SubNavigationPosition::End;
|
||||
protected static ?SubNavigationPosition $subNavigationPosition = SubNavigationPosition::Top;
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
|
||||
@@ -10,7 +10,6 @@ use Filament\Support\Icons\Heroicon;
|
||||
class LoansCluster extends Cluster
|
||||
{
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBanknotes;
|
||||
// protected static string|BackedEnum|null $activeNavigationIcon = Heroicon::Banknotes;
|
||||
|
||||
protected static ?SubNavigationPosition $subNavigationPosition = SubNavigationPosition::Top;
|
||||
|
||||
|
||||
143
app/Modules/AppHelpers/Repositories/DateHelper.php
Normal file
143
app/Modules/AppHelpers/Repositories/DateHelper.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\AppHelpers\Repositories;
|
||||
|
||||
class DateHelper
|
||||
{
|
||||
/**
|
||||
* Month as number
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function monthsAsNumber(): array
|
||||
{
|
||||
$month = [];
|
||||
|
||||
for ($m = 1; $m <= 12; $m++) {
|
||||
$month[] = str_pad(strval($m), 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
return $month;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static numbers for months
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function staticNumberMonths(): array
|
||||
{
|
||||
return [
|
||||
'01' => '01',
|
||||
'02' => '02',
|
||||
'03' => '03',
|
||||
'04' => '04',
|
||||
'05' => '05',
|
||||
'06' => '06',
|
||||
'07' => '07',
|
||||
'08' => '08',
|
||||
'09' => '09',
|
||||
'10' => '10',
|
||||
'11' => '11',
|
||||
'12' => '12',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Years until
|
||||
*
|
||||
* @param int|int $max
|
||||
*
|
||||
* @return array<string|int, string|int>
|
||||
*/
|
||||
public static function yearsUntil(int $max = 50): array
|
||||
{
|
||||
$years = [];
|
||||
|
||||
$currentData = 2024;
|
||||
|
||||
for ($i = 0; $i <= $max; $i++) {
|
||||
$years[] = intval($currentData) + $i;
|
||||
}
|
||||
|
||||
return $years;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static numbers for years
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function staticNumberYears(): array
|
||||
{
|
||||
return [
|
||||
'2024' => '2024',
|
||||
'2025' => '2025',
|
||||
'2026' => '2026',
|
||||
'2027' => '2027',
|
||||
'2028' => '2028',
|
||||
'2029' => '2029',
|
||||
'2030' => '2030',
|
||||
'2031' => '2031',
|
||||
'2032' => '2032',
|
||||
'2033' => '2033',
|
||||
'2034' => '2034',
|
||||
'2035' => '2035',
|
||||
'2036' => '2036',
|
||||
'2037' => '2037',
|
||||
'2038' => '2038',
|
||||
'2039' => '2039',
|
||||
'2040' => '2040',
|
||||
'2041' => '2041',
|
||||
'2042' => '2042',
|
||||
'2043' => '2043',
|
||||
'2044' => '2044',
|
||||
'2045' => '2045',
|
||||
'2046' => '2046',
|
||||
'2047' => '2047',
|
||||
'2048' => '2048',
|
||||
'2049' => '2049',
|
||||
'2050' => '2050',
|
||||
'2051' => '2051',
|
||||
'2052' => '2052',
|
||||
'2053' => '2053',
|
||||
'2054' => '2054',
|
||||
'2055' => '2055',
|
||||
'2056' => '2056',
|
||||
'2057' => '2057',
|
||||
'2058' => '2058',
|
||||
'2059' => '2059',
|
||||
'2060' => '2060',
|
||||
'2061' => '2061',
|
||||
'2062' => '2062',
|
||||
'2063' => '2063',
|
||||
'2064' => '2064',
|
||||
'2065' => '2065',
|
||||
'2066' => '2066',
|
||||
'2067' => '2067',
|
||||
'2068' => '2068',
|
||||
'2069' => '2069',
|
||||
'2070' => '2070',
|
||||
'2071' => '2071',
|
||||
'2072' => '2072',
|
||||
'2073' => '2073',
|
||||
'2074' => '2074',
|
||||
'2075' => '2075',
|
||||
'2076' => '2076',
|
||||
'2077' => '2077',
|
||||
'2078' => '2078',
|
||||
'2079' => '2079',
|
||||
'2080' => '2080',
|
||||
'2081' => '2081',
|
||||
'2082' => '2082',
|
||||
'2083' => '2083',
|
||||
'2084' => '2084',
|
||||
'2085' => '2085',
|
||||
'2086' => '2086',
|
||||
'2087' => '2087',
|
||||
'2088' => '2088',
|
||||
'2089' => '2089',
|
||||
'2090' => '2090',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user