In Laravel, storing values to a join table without defining Eloquent relationship
As part of the onboarding process for my Laravel app, a user can enter the ages of his or her children. A user can have many children, and so there needs to be a
kids table that stores
user_id (which references
id on the
users table), and
kid_age. This seems like a basic one-to-many relationship—a user can have many children.
In a profile view elsewhere in the app, I have display back the ages of each child. However, that's the only point in the app where the kids make an appearance. It seems like overkill to create an entire
kid model just to manage the parent to child relationship.
Is there a lighter-weight way to assign values to a join table? If so, how would I save data to that table without defining the relationship between two models?
Without using a model, you'd have to manage the tables manually in the database. I think it is far and away easier to use a model for this, so that you can create, update, delete, and sync
kid models effortlessly using Laravel functions. Because you've followed the proper naming conventions for tables and ID columns, it should only take a couple of lines of code to create the new model. Seems light-weight enough to me.
Sorry for not providing another solution, but my take is go with the Laravel solution.
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?