Overview
The Category model represents transaction categories in Cashify. Categories help organize transactions into types (income, expense, correction, transfer) with customizable colors and icons for visual identification.Properties
Unique identifier for the category
Foreign key referencing the user who owns this category
Name of the category (e.g., “Groceries”, “Salary”, “Utilities”)
Type of the categoryAllowed values:
income- For income transactionsexpense- For expense transactionscorrection- For balance correctionstransfer- For transfers between accounts
Color identifier for visual representationDefault:
"gray"Icon identifier for visual representationDefault:
"image"When the category was created
When the category was last updated
Fillable Attributes
The following attributes can be mass-assigned:nametypecoloricon
Public Properties
$shade
The color shade value used for Tailwind CSS classes. Type:integer
Default: 200
Relationships
user()
Returns the user who owns this category. Type: BelongsTo Returns:Illuminate\Database\Eloquent\Relations\BelongsTo
transactions()
Returns all transactions associated with this category. Type: HasMany Returns:Illuminate\Database\Eloquent\Relations\HasMany
Color Methods
The Category model uses theHasColor trait, which provides color management functionality.
getColorClassAttribute()
Returns the full Tailwind CSS class for the category’s color. Returns:string
Shade: Uses the model’s $shade property (200)
setColorAttribute()
Sets the color attribute for the category. 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 categories table has the following indexes for optimized queries:name- For searching categories by nametype- For filtering by category typeuser_id- For filtering by useruser_id, type- Composite index for user-type queries
Cascade Deletion
Categories 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