mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
finish seed box basic
This commit is contained in:
@@ -13,23 +13,28 @@ class CreateSeedBoxRecord extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SeedBoxRecordResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
public function create(bool $another = false): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$data['uid'] = auth()->id();
|
||||
$data['type'] = SeedBoxRecord::TYPE_ADMIN;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
$seedBoxRep = new SeedBoxRepository();
|
||||
$data['status'] = SeedBoxRecord::STATUS_ALLOWED;
|
||||
$rep = new SeedBoxRepository();
|
||||
try {
|
||||
return $seedBoxRep->store($data);
|
||||
$this->record = $rep->store($data);
|
||||
$this->notify('success', $this->getCreatedNotificationMessage());
|
||||
if ($another) {
|
||||
// Ensure that the form record is anonymized so that relationships aren't loaded.
|
||||
$this->form->model($this->record::class);
|
||||
$this->record = null;
|
||||
|
||||
$this->fillForm();
|
||||
|
||||
return;
|
||||
}
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
} catch (\Exception $exception) {
|
||||
//this wont work...
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Resources\System\SeedBoxRecordResource\Pages;
|
||||
|
||||
use App\Filament\Resources\System\SeedBoxRecordResource;
|
||||
use App\Repositories\SeedBoxRepository;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
@@ -16,4 +17,17 @@ class EditSeedBoxRecord extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function save(bool $shouldRedirect = true): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$rep = new SeedBoxRepository();
|
||||
try {
|
||||
$this->record = $rep->update($data, $this->record->id);
|
||||
$this->notify('success', $this->getSavedNotificationMessage());
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user