Linked User accounts. ie Parents login with kids accounts.
Hello,
I'm building a club management system. One thing I would like to achieve is to have a Parental Login whereby the parents can create kids accounts. The main parental account would manage all payments and subscriptions for club classes. So the parent could also be doing their own class, their kids could be doing a class too... think around the notion of a karate or dance club for example.
The kids account can have a separate login, their own dashboard, view club content but cannot manage their payments or buy thing from the club shop for example. Parental account will manage the kids account, ie reset password or update kids profile details.
When the child reaches 18 years old their account can be converted to a full adult account where they can manage their own payments/purchases.
Is this possible?
Do I look at linking user accounts and assigning roles or creating just a parental account with 'profile' attached for the kids?
@linzeclark Yes, this is possible. I’ve worked on a couple of applications with the concept of “child” and “adult” accounts in the past, mainly within sports.
The bottom line is, try not to over-complicate the problem. Adults have accounts. Children have accounts. If child accounts can’t make payments then you can encode that logic in something like a policy that checks the birthdate of the account:
class PaymentPolicy
{
public function create(User $user): bool
{
return $user->birth_date->age >= 18;
}
}
For the adult-to-child relationship, you can either add a nullable foreign to your users that denotes which account “owns” another account, or a pivot table if you want a child account to potentially be “owned” by multiple accounts, i.e. both parents of the child.
@martinbean Thank you for your reply, I have now implemented a parent and child accounts. Like you said, not to over complicate it, I used a column 'parent_id and setup roles for the users and assigned a role 'child' to a user. Then when a parent registers their account they can create accounts for their kids.
class User extends Model
{
protected $fillable = ['name', 'email', 'password', 'role_id', 'parent_id', 'birthdate'];
public function role()
{
return $this->belongsTo(Role::class);
}
public function parent()
{
return $this->belongsTo(User::class, 'parent_id');
}
public function children()
{
return $this->hasMany(User::class, 'parent_id');
}
public function isParent()
{
return $this->role->name === 'parent';
}
public function isChild()
{
return $this->role->name === 'child';
}
}
The parent is the team owner and manages team members. Bills are charged to the team and can be settled by any member of the team, but likely the owner.
@Snapey thanks, yes I've been considering the teams setup, I think that's where I'm heading.
I'm using cashier and stripe to handle class subscriptions for parents and kids so I'll see how I get on, as that's my task for today - parental subscriptions and billing. : )