Overview
The Account model represents financial accounts (e.g., bank accounts, wallets, credit cards) in Cashify. Each account belongs to a user and tracks a balance with customizable color coding.Properties
Unique identifier for the account
Foreign key referencing the user who owns this account
Name of the account (e.g., “Chase Checking”, “Savings Account”)
Current balance of the account with precision of 15 digits and 2 decimal placesDefault:
0.00Color identifier for visual representationDefault:
"gray"When the account was created
When the account was last updated
Fillable Attributes
The following attributes can be mass-assigned:namebalancecolor
Relationships
user()
Returns the user who owns this account. Type: BelongsTo Returns:Illuminate\Database\Eloquent\Relations\BelongsTo
transactions()
Returns all transactions associated with this account. Type: HasMany Returns:Illuminate\Database\Eloquent\Relations\HasMany
Color Methods
The Account model uses theHasColor trait, which provides color management functionality.
getColorClassAttribute()
Returns the full Tailwind CSS class for the account’s color. Returns:string
Default shade: 300
setColorAttribute()
Sets the color attribute for the account. Parameters:string $color
getColorAttribute()
Gets the color attribute value. Returns:string
getAvailableColors()
Returns an array of all available colors. Returns:array
Static method
getDefaultColor()
Returns the default color value. Returns:string
Static method
Database Indexes
The accounts table has the following indexes for optimized queries:name- For searching accounts by nameuser_id, balance- Composite index for user-balance queries
Cascade Deletion
Accounts are automatically deleted when their associated user is deleted (cascade on delete).Traits
HasFactory- Enables model factories for testingHasColor- Provides color management functionality with Tailwind CSS integration