good
This commit is contained in:
57
app/Filament/Resources/Coupons/CouponResource.php
Normal file
57
app/Filament/Resources/Coupons/CouponResource.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Coupons;
|
||||
|
||||
use App\Filament\Resources\Coupons\Pages\ListCoupons;
|
||||
use App\Filament\Resources\Coupons\Pages\ViewCoupon;
|
||||
use App\Filament\Resources\Coupons\Schemas\CouponInfolist;
|
||||
use App\Filament\Resources\Coupons\Tables\CouponsTable;
|
||||
use App\Models\Coupon;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CouponResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Coupon::class;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'phone';
|
||||
|
||||
protected static ?string $navigationLabel = 'Coupons';
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedTicket;
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return CouponInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return CouponsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListCoupons::route('/'),
|
||||
'view' => ViewCoupon::route('/{record}'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Coupons/Pages/ListCoupons.php
Normal file
11
app/Filament/Resources/Coupons/Pages/ListCoupons.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Coupons\Pages;
|
||||
|
||||
use App\Filament\Resources\Coupons\CouponResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCoupons extends ListRecords
|
||||
{
|
||||
protected static string $resource = CouponResource::class;
|
||||
}
|
||||
11
app/Filament/Resources/Coupons/Pages/ViewCoupon.php
Normal file
11
app/Filament/Resources/Coupons/Pages/ViewCoupon.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Coupons\Pages;
|
||||
|
||||
use App\Filament\Resources\Coupons\CouponResource;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewCoupon extends ViewRecord
|
||||
{
|
||||
protected static string $resource = CouponResource::class;
|
||||
}
|
||||
24
app/Filament/Resources/Coupons/Schemas/CouponInfolist.php
Normal file
24
app/Filament/Resources/Coupons/Schemas/CouponInfolist.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Coupons\Schemas;
|
||||
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class CouponInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextEntry::make('phone')
|
||||
->copyable(),
|
||||
TextEntry::make('code')
|
||||
->copyable(),
|
||||
TextEntry::make('created_at')
|
||||
->dateTime(),
|
||||
TextEntry::make('updated_at')
|
||||
->dateTime(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
app/Filament/Resources/Coupons/Tables/CouponsTable.php
Normal file
41
app/Filament/Resources/Coupons/Tables/CouponsTable.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Coupons\Tables;
|
||||
|
||||
use App\Filament\Tables\Filters\CreatedAtDateFilter;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CouponsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->sortable(),
|
||||
TextColumn::make('phone')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->copyable(),
|
||||
TextColumn::make('code')
|
||||
->sortable()
|
||||
->copyable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
CreatedAtDateFilter::make(),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PhoneVerifications\Pages;
|
||||
|
||||
use App\Filament\Resources\PhoneVerifications\PhoneVerificationResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPhoneVerifications extends ListRecords
|
||||
{
|
||||
protected static string $resource = PhoneVerificationResource::class;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PhoneVerifications\Pages;
|
||||
|
||||
use App\Filament\Resources\PhoneVerifications\PhoneVerificationResource;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewPhoneVerification extends ViewRecord
|
||||
{
|
||||
protected static string $resource = PhoneVerificationResource::class;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PhoneVerifications;
|
||||
|
||||
use App\Filament\Resources\PhoneVerifications\Pages\ListPhoneVerifications;
|
||||
use App\Filament\Resources\PhoneVerifications\Pages\ViewPhoneVerification;
|
||||
use App\Filament\Resources\PhoneVerifications\Schemas\PhoneVerificationInfolist;
|
||||
use App\Filament\Resources\PhoneVerifications\Tables\PhoneVerificationsTable;
|
||||
use App\Models\PhoneVerification;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class PhoneVerificationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = PhoneVerification::class;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'phone';
|
||||
|
||||
protected static ?string $navigationLabel = 'OTP Verifications';
|
||||
|
||||
protected static ?string $modelLabel = 'OTP verification';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'OTP verifications';
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedKey;
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return PhoneVerificationInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return PhoneVerificationsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListPhoneVerifications::route('/'),
|
||||
'view' => ViewPhoneVerification::route('/{record}'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PhoneVerifications\Schemas;
|
||||
|
||||
use Filament\Infolists\Components\IconEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class PhoneVerificationInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextEntry::make('phone')
|
||||
->copyable(),
|
||||
TextEntry::make('otp')
|
||||
->label('OTP')
|
||||
->copyable(),
|
||||
TextEntry::make('expires_at')
|
||||
->dateTime(),
|
||||
IconEntry::make('verified')
|
||||
->boolean(),
|
||||
TextEntry::make('created_at')
|
||||
->dateTime(),
|
||||
TextEntry::make('updated_at')
|
||||
->dateTime(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PhoneVerifications\Tables;
|
||||
|
||||
use App\Filament\Tables\Filters\CreatedAtDateFilter;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class PhoneVerificationsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->sortable(),
|
||||
TextColumn::make('phone')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->copyable(),
|
||||
TextColumn::make('otp')
|
||||
->label('OTP')
|
||||
->copyable(),
|
||||
TextColumn::make('expires_at')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
IconColumn::make('verified')
|
||||
->boolean()
|
||||
->sortable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
CreatedAtDateFilter::make(),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
50
app/Filament/Tables/Filters/CreatedAtDateFilter.php
Normal file
50
app/Filament/Tables/Filters/CreatedAtDateFilter.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tables\Filters;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\Indicator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CreatedAtDateFilter
|
||||
{
|
||||
public static function make(): Filter
|
||||
{
|
||||
return Filter::make('created_at')
|
||||
->label('Date')
|
||||
->schema([
|
||||
DatePicker::make('from')
|
||||
->label('From'),
|
||||
DatePicker::make('until')
|
||||
->label('Until'),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query
|
||||
->when(
|
||||
$data['from'] ?? null,
|
||||
fn (Builder $query, string $date): Builder => $query->whereDate('created_at', '>=', $date),
|
||||
)
|
||||
->when(
|
||||
$data['until'] ?? null,
|
||||
fn (Builder $query, string $date): Builder => $query->whereDate('created_at', '<=', $date),
|
||||
);
|
||||
})
|
||||
->indicateUsing(function (array $data): array {
|
||||
$indicators = [];
|
||||
|
||||
if ($data['from'] ?? null) {
|
||||
$indicators[] = Indicator::make('From '.Carbon::parse($data['from'])->toFormattedDateString())
|
||||
->removeField('from');
|
||||
}
|
||||
|
||||
if ($data['until'] ?? null) {
|
||||
$indicators[] = Indicator::make('Until '.Carbon::parse($data['until'])->toFormattedDateString())
|
||||
->removeField('until');
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user