46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Resources\GatewayResource\Pages;
|
|
|
|
use App\Admin\Resources\GatewayResource;
|
|
use App\Helpers\ExtensionHelper;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class CreateGateway extends CreateRecord
|
|
{
|
|
protected static string $resource = GatewayResource::class;
|
|
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
$data['type'] = 'gateway';
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function handleRecordCreation(array $data): Model
|
|
{
|
|
$data['enabled'] = true;
|
|
$record = static::getModel()::create(\Arr::except($data, ['settings']));
|
|
|
|
if (!isset($data['settings'])) {
|
|
return $record;
|
|
}
|
|
|
|
foreach ($data['settings'] as $key => $value) {
|
|
if (is_null($value)) {
|
|
continue;
|
|
}
|
|
$record->settings()->updateOrCreate([
|
|
'key' => $key,
|
|
], [
|
|
'value' => $value,
|
|
]);
|
|
}
|
|
|
|
ExtensionHelper::call($record, 'enabled', [$record], mayFail: true);
|
|
|
|
return $record;
|
|
}
|
|
}
|