-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathLicenseResource.php
More file actions
129 lines (121 loc) · 4.81 KB
/
LicenseResource.php
File metadata and controls
129 lines (121 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\LicenseResource\Pages;
use App\Filament\Resources\LicenseResource\RelationManagers;
use App\Models\License;
use Filament\Actions;
use Filament\Forms;
use Filament\Resources\Resource;
use Filament\Schemas;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Table;
class LicenseResource extends Resource
{
protected static ?string $model = License::class;
protected static \BackedEnum|string|null $navigationIcon = 'heroicon-o-key';
public static function form(Schema $schema): Schema
{
return $schema
->schema([
Schemas\Components\Section::make('License Information')
->schema([
Forms\Components\TextInput::make('id')
->disabled(),
Forms\Components\TextInput::make('anystack_id')
->maxLength(36)
->disabled(),
Forms\Components\Select::make('user_id')
->relationship('user', 'email')
->searchable(['id', 'email']),
Forms\Components\Select::make('subscription_item_id')
->relationship('subscriptionItem', 'id')
->nullable()
->searchable(),
Forms\Components\TextInput::make('policy_name')
->label('Plan')
->disabled(),
Forms\Components\TextInput::make('key')
->disabled(),
Forms\Components\DateTimePicker::make('expires_at')
->disabled(),
Forms\Components\DateTimePicker::make('created_at')
->disabled(),
Forms\Components\Toggle::make('is_suspended')
->label('Suspended')
->disabled(),
])
->columns(2),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('id', 'desc')
->columns([
Tables\Columns\TextColumn::make('id')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('user.email')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('subscription_item_id')
->label('Subscription Item')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('key')
->searchable()
->copyable(),
Tables\Columns\TextColumn::make('policy_name')
->label('Plan')
->searchable(),
Tables\Columns\TextColumn::make('expires_at')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable(),
Tables\Columns\IconColumn::make('is_suspended')
->boolean()
->label('Suspended')
->sortable(),
])
->filters([
Tables\Filters\TernaryFilter::make('is_suspended')
->label('Suspended'),
])
->actions([
Actions\ActionGroup::make([
Actions\EditAction::make(),
Actions\Action::make('viewUser')
->label('View User')
->icon('heroicon-o-user')
->color('primary')
->url(fn (License $record) => route('filament.admin.resources.users.edit', ['record' => $record->user_id]))
->openUrlInNewTab()
->visible(fn (License $record) => $record->user_id !== null),
])
->label('Actions')
->icon('heroicon-m-ellipsis-vertical'),
])
->defaultPaginationPageOption(25)
->bulkActions([])
->recordUrl(
fn ($record) => static::getUrl('edit', ['record' => $record])
);
}
public static function getRelations(): array
{
return [
RelationManagers\UserRelationManager::class,
RelationManagers\SubscriptionItemRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListLicenses::route('/'),
'edit' => Pages\EditLicense::route('/{record}/edit'),
];
}
}