123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
-
- namespace App\Filament\Company\Resources\Banking\AccountResource\Pages;
-
- use App\Filament\Company\Resources\Banking\AccountResource;
- use App\Models\Banking\Account;
- use App\Traits\HandlesResourceRecordCreation;
- use Filament\Actions;
- use Filament\Resources\Pages\CreateRecord;
- use Filament\Support\Exceptions\Halt;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Auth;
-
- class CreateAccount extends CreateRecord
- {
- use HandlesResourceRecordCreation;
-
- protected static string $resource = AccountResource::class;
-
- protected function getRedirectUrl(): string
- {
- return $this->previousUrl;
- }
-
- protected function mutateFormDataBeforeCreate(array $data): array
- {
- $data['enabled'] = (bool)$data['enabled'];
-
- return $data;
- }
-
- /**
- * @throws Halt
- */
- protected function handleRecordCreation(array $data): Model
- {
- $user = Auth::user();
-
- if (!$user) {
- throw new Halt('No authenticated user found.');
- }
-
- return $this->handleRecordCreationWithUniqueField($data, new Account(), $user);
- }
- }
|