I'm working on an admin tool app using Laravel/Vue/Inertia for a club that I belong to, and I'm trying to determine how best to create the Eloquent relationships for three models.
Every year, each member is required to put in a certain number of work hours around the club helping out. The club is broken out into multiple areas, referred to as Disciplines. When a member puts in their time, currently they fill out a paper slip that contains the discipline, the date, the hours, and requires an approval signature by the "owner" of a discipline or a designated approver for the area. This is what I want to implement in my app. When a WorkHours entry is created, the user will enter the date, number of hours, discipline, and a designated approver for that discipline.
What this means is that a user record can be both a) an approver on a Discipline and b) a user for whom the WorkHours record is being submitted (but not both on one WorkHours record, for obviuos reasons).
So as I see it, I need three models and the following fields based on the facts that:
approvers() = ->belongsToMany(User::class)
member() = ->belongsTo(User::class)as
discipline() = ->belongsTo(Discipline::class)
approver() = ->hasOne(User::class)as
disciplines() = ->belongsToMany(Discipline::class)
workHours() = ->hasMany(WorkHours::class)
And my tables and relevant fields would look like this:
Does that all seem correct? Or is there a better way I could define my relationships?