Overview
The Transaction model represents financial transactions in Cashify. Each transaction belongs to a user, is associated with an account and category, and tracks the amount and details of the financial activity.Properties
Unique identifier for the transaction
Foreign key referencing the user who owns this transaction
Foreign key referencing the category of this transaction
Foreign key referencing the account this transaction belongs to
Title or description of the transaction
Transaction amount with precision of 15 digits and 2 decimal placesDefault:
0.00Additional details or notes about the transaction
When the transaction was created
When the transaction was last updated
Mass Assignment
All attributes are mass-assignable (using$guarded = []), which means you can set any field when creating or updating a transaction.
Relationships
user()
Returns the user who owns this transaction. Type: BelongsTo Returns:Illuminate\Database\Eloquent\Relations\BelongsTo
account()
Returns the account this transaction is associated with. Type: BelongsTo Returns:Illuminate\Database\Eloquent\Relations\BelongsTo
category()
Returns the category of this transaction. Type: BelongsTo Returns:Illuminate\Database\Eloquent\Relations\BelongsTo
Database Indexes
The transactions table has the following indexes for optimized queries:title- For searching transactions by titleuser_id- For filtering by usercategory_id- For filtering by categoryaccount_id- For filtering by accountuser_id, category_id- Composite index for user-category queriesuser_id, account_id- Composite index for user-account queries
Cascade Deletion
Transactions are automatically deleted when their associated user, category, or account is deleted (cascade on delete).Traits
HasFactory- Enables model factories for testing