How to populate table when user registers
So,
I have created a new table for API calls when users have specific plans they buy. But I need to populate that table once the user registers with that specific plan. I can't seem to be able to understand how to do it properly, can someone guide me?
I added a new controller and model for this table and new routes and they work via API (they are meant for api only) but the table is empty right now and I want to populate it automatically basically when a user is registered to start the table with default values. (Each table row is tied to a user_id basically). I know how to do it per se but don't know where to do it.
I also want this table to be for each plan (I plan on having around 10 to start but then much more), so if the user buy 1 plan he has access to 1 table (and api calls that come with it) but if he has 4 plans he has access to 4 tables. This will generate a 'lot' of tables. My question here is should I do it in a table for each plan or 1 huge table and have a column for each plan?
Hi there,
A quick way to do that is to update the register controller and add the extra logic in there:
In there you can define the extra actions that you want to take right after the user registration. A more advanced option is to fire an event after the registration, but for this you would need to implement events and listners as described in this course here:
Regarding the tables, I think that with the defatul Wave API and permissions, having separate tables will be a good approach as you can limit the access to each table using the default roles. An alternative option would be to have just one table with Many to Many relationship for your plans and Users and have a custom API controller to handle that logic.
Hope that this helps!