amount) || (int) $transaction->amount != $transaction->amount || $transaction->amount <= 0) { throw new \InvalidArgumentException('Transaction amount must be a positive whole number of minutes.'); } if ((int) $transaction->from_account_id === (int) $transaction->to_account_id) { throw new \InvalidArgumentException('Transaction from and to account must differ.'); } if (Account::whereKey([$transaction->from_account_id, $transaction->to_account_id])->count() !== 2) { throw new \InvalidArgumentException('Transaction from and to account must exist.'); } if (!TransactionType::whereKey($transaction->transaction_type_id)->exists()) { throw new \InvalidArgumentException('Transaction type must exist.'); } }); } /** * Get the index name for the model. * * @return string */ public function searchableAs() { return 'transactions_index'; } /** * Convert the transaction model to a searchable array. * * @return array */ public function toSearchableArray() { return [ 'id' => $this->id, 'from_account_id' => $this->from_account_id, 'to_account_id' => $this->to_account_id, 'amount' => $this->amount, 'description' => $this->description ?? '', 'created_at' => $this->created_at?->format('Y-m-d H:i:s'), ]; } public function accountFrom() { return $this->belongsTo(Account::class, 'from_account_id'); } public function accountTo() { return $this->belongsTo(Account::class, 'to_account_id'); } public function creator() { return $this->belongsTo(User::class, 'creator_user_id'); } /** * Get the transaction type that owns the transaction. */ public function transactionType() { return $this->belongsTo(TransactionType::class); } }