Closed jugglingdev closed 3 months ago
Looks good overall. Nice job defining keyType and incrementing for the UUID primary keys!
1. Remove column name parameters from your belongsTo
and hasMany
relationships. Those are only necessary when your project does not follow standard naming conventions. For example, when you define that Child belongs to Dad, Laravel automatically assumes Child will have a dad_id
field that refers to the id
table on Dad.
Tip: If you ever find that you have to specify the field names to make the relationship work correctly, you are probably using the wrong relationship type. We made this mistake early in our own project.
2. Create separate use
lines for each trait to make future trait additions/removals easier to review. It is much easier to see that a line has been inserted or deleted than to see what was changed within a long list of traits. For example, instead of use HasFactory, HasUuids;
create two separate lines:
use HasFactory;
use HasUuids;
3. Define casts() for additional fields:
date_of_birth
as immutable_date
so Carbon operations on the date do not accidentally update the table. This prevents $child->date_of_birth->addDay()
from updating the table, which could happen during a comparison operation etc. Instead, you must explicitly assign the value like this $child->date_of_birth = $child->date_of_birth->addDay()
;monthly_child_support
as decimal:2
so that any values are rounded to two digits before being stored. We should also change the field type in the underlying Dad table migration from float('monthly_child_support')
to decimal('monthly_child_support', 6, 2)
to avoid precision problems. Parameters "6, 2" will allow the field to store 6 total digits with two of the digits after the decimal point (e.g. NNNN.NN or 1234.56).child_support
same as above. Change migration from float
to decimal(6,2)
and cast as decimal:2
Learn more: Here's a nice SO conversation about when to add casts to fields...
By default, attributes will be casted to the type of column defined in the table. So, if your column is an integer, then it will be casted as int. But, what happens if you want to modify this behavior for specific fields? That's when attribute casting enters the scene.
4. Run composer lint
to apply Laravel code standard fixes. When I forget this step before I have committed my code, I usually commit with message such as chore: composer lint
or chore: lint
.
@jason-klein I made the updates as you explained.
I found two fields for enums: ethnicity and marital status. In the future, we will need to update these to match federal regulations.
After building out these models, I do believe it would be worthwhile to revisit the ERD as a group and re-examine defined relationships to make sure they align with business needs.
Please let me know if there are any further changes that need to be made.
Thank you!
Please review these model files.
I added @property annotations, fields, and HasUuids, HasMany, and BelongTo as appropriate.