mirror of
https://github.com/pelican-dev/panel.git
synced 2025-09-08 23:08:37 +02:00
50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Admin\Resources\WebhookResource\RelationManagers;
|
|
|
|
use App\Models\WebhookConfiguration;
|
|
use App\Models\WebhookEvent;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Tables\Actions\Action;
|
|
use Filament\Tables\Actions\DeleteAction;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
/**
|
|
* @method WebhookConfiguration getOwnerRecord()
|
|
*/
|
|
class EventsRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'webhookEvents';
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->heading('')
|
|
->columns([
|
|
TextColumn::make('id'),
|
|
TextColumn::make('name'),
|
|
])
|
|
->headerActions([
|
|
Action::make('create')
|
|
->form(fn () => [
|
|
TextInput::make('name')
|
|
->inlineLabel()
|
|
->live()
|
|
->required(),
|
|
])
|
|
->action(function (array $data) {
|
|
$id = WebhookEvent::firstOrCreate([
|
|
'name' => $data['name'],
|
|
]);
|
|
$this->getOwnerRecord()->webhookEvents()->sync([$id]);
|
|
}),
|
|
])
|
|
->actions([
|
|
DeleteAction::make()
|
|
->authorize(fn (WebhookConfiguration $config) => auth()->user()->can('delete', $config)),
|
|
]);
|
|
}
|
|
}
|