lundi 7 novembre 2016

Inserting with relationships in laravel

I am facing a problem in Laravel 5.3 that I looked the docs and also searched web but didn't find anything on it.

I am using Laravel Relationships to join two tables. Now I want the data to be updated on both the tables at the same time after the user submits a form. The catch in this is the first table is the primary one say "users" and second one "xyz" belongsTo the first table. The table "xyz" contains "users_id" column that connects both the tables. And obviously "users_id" is the "id" column of "users" table.

Now the problem arriving is that I want to insert the data in "users" table (that is easily done) and "xyz" table at the same time. The User::create() function will create the user data easily and it is working also but for inserting the data in "xyz" table I will be needing the "user_id" column data and ID will not be generated until the user is created as ID column has Auto-Increment attribute activated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire