Be great if someone can drop me some help here, I understand pretty well the concepts of ORM / Databases / MVC but first time doing boots to the ground as it were.
In Laravel, trying to get my head around relationships, and pushing data into the models, in terms of downstream relationships.
For simple terms, let's say I have
1 x User Model (Contains their id, email, name)
1 x User Data Model (Maybe contains some other attributes i don't want in the main user table)
My User model is using a hasOne with the User Data Model, the User Data Model belongs to User.
Questions at this point:
1. Do I need to manually put the DB fields in the User Data table, for User_ID or should the ORM be doing this for me?
2. I create some data, for example using SEEDS in Laravel
This works fine, but for adding relating data at the same time, and linking it back to the correct user... Is this completely wrong?
My brain is yelling yes, but not 100% sure!
Thanks in advance, I know this is a long one.
In Laravel, trying to get my head around relationships, and pushing data into the models, in terms of downstream relationships.
For simple terms, let's say I have
1 x User Model (Contains their id, email, name)
1 x User Data Model (Maybe contains some other attributes i don't want in the main user table)
My User model is using a hasOne with the User Data Model, the User Data Model belongs to User.
Questions at this point:
1. Do I need to manually put the DB fields in the User Data table, for User_ID or should the ORM be doing this for me?
2. I create some data, for example using SEEDS in Laravel
PHP:
$player = User::create([
'Name' => 'Olli',
'Email' => '[email protected]',
]);
This works fine, but for adding relating data at the same time, and linking it back to the correct user... Is this completely wrong?
PHP:
$userid = $user->id;
UserData::create ([
'PlayerID' => $userid,
'attribute1' => '14',
'attribute2' => '14',
'attribute3' => '14',
]);
My brain is yelling yes, but not 100% sure!
Thanks in advance, I know this is a long one.