clientId = request()->integer('client_id'); } public function getBreadcrumbs(): array { $client = $this->getClient(); if (! $client) { return parent::getBreadcrumbs(); } return [ ClientResource::getUrl('view', ['record' => $client->id]) => $client->company, ClientResource::getUrl('view', ['record' => $client->id]).'?activeRelationManager=4' => 'Expenses', $this->getResource()::getUrl('create', ['client_id' => $client->id]) => 'Create', ]; } protected function getClient(): Client|null { if (! $this->clientId) { return null; } return Client::find($this->clientId); } protected function mutateFormDataBeforeCreate(array $data): array { return $this->getFormDataMutation($data); } public function getFormDataMutation(array $data): array { return Arr::except($data, ['client', 'transactions']); } protected function afterCreate(): void { $transactions = $this->form->getState()['transactions'] ?? []; try { $branch = $this->getRecord()->branch; foreach ($transactions as $transaction) { $data = [ 'branch_id' => $branch->id, 'happened_on' => $this->getRecord()->happened_on, ...$transaction, ]; $payload = new CreateTransactionDTO(data: $data, transactionable: $this->getRecord()); Pipeline::send(passable: $payload)->through( [ CreateTransactionAction::class, ] )->thenReturn(); } $this->commitDatabaseTransaction(); } catch (Exception $exception) { $this->rollBackDatabaseTransaction(); throw new LogicException('Failed to save transactions : '.$exception->getMessage()); } } }