-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathPluginsRelationManager.php
More file actions
88 lines (74 loc) · 3.24 KB
/
PluginsRelationManager.php
File metadata and controls
88 lines (74 loc) · 3.24 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
<?php
namespace App\Filament\Resources\PluginBundleResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Artisan;
class PluginsRelationManager extends RelationManager
{
protected static string $relationship = 'plugins';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $title = 'Included Plugins';
public function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\ImageColumn::make('logo_path')
->label('')
->disk('public')
->circular()
->size(40),
Tables\Columns\TextColumn::make('name')
->label('Package Name')
->searchable()
->fontFamily('mono'),
Tables\Columns\TextColumn::make('user.email')
->label('Developer'),
Tables\Columns\TextColumn::make('activePrice.amount')
->label('Retail Price')
->formatStateUsing(fn (?int $state): string => $state ? '$'.number_format($state / 100, 2) : 'N/A'),
Tables\Columns\TextColumn::make('sort_order')
->label('Order')
->sortable()
->getStateUsing(fn ($record) => $record->pivot->sort_order ?? 0),
])
->reorderable('sort_order')
->defaultSort('sort_order')
->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->recordSelectSearchColumns(['name'])
->form(fn (Tables\Actions\AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Toggle::make('grant_to_existing_owners')
->label('Grant to existing bundle owners')
->helperText('Create free licenses for users who already purchased this bundle and send them an email.')
->default(true),
])
->after(function (array $data) {
if (! ($data['grant_to_existing_owners'] ?? false)) {
return;
}
/** @var \App\Models\PluginBundle $bundle */
$bundle = $this->getOwnerRecord();
$plugin = \App\Models\Plugin::find($data['recordId']);
if (! $plugin) {
return;
}
Artisan::call('plugins:grant-to-bundle-owners', [
'bundle' => $bundle->slug,
'plugin' => $plugin->name,
]);
}),
])
->actions([
Tables\Actions\DetachAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DetachBulkAction::make(),
]),
]);
}
}