Providing more information could help in getting a reply, as there are a few ways to insert data in to a database using Laravel.
How are you inserting.... DB::TABLE.... Model::create ... $var = new Model()... etc.
I'm doing this:
$show = new Show;
$show_title = $show->ShowTitle ?: new ShowTitle;
$show_title->data_entered = Input::get('data_entered');
$show->save();
$show->new_title()->save($show_title);
I need to get the ID for the record created in ShowTitle.
The reason being is that Show needs to be related to the new record in ShowTitle (id in Show needs to be the same as show_id in ShowTitle). But the ID for the new record in ShowTitle also needs to related to Show (id in ShowTitle needs to be the same as title_id in Show).
Sorry, yesterday ended up being a very busy.
If your relationships are setup in the models, you should be able to simply save the records and Laravel will handle the id's.
You might try a dd of the $show after the first save, to see if the id was was created in $show - it should have one.
$show->new_title()->save($show_title) , should save the $show_title model record and assign the id of the $show record to show_id in the $show_title model.
I'm assuming the new_title() is a Laravel relationship, hasMany, belongsTo, etc..
A dd of $show->toArray() after the new_title()->save might also show if the new_title() has any data in it.
Humm, since you make a change to the $show after the first save, you might do a $show->save() after the new_title()->save($show_title), I am drawing a blank on if does this automatically, but I couldn't hurt.
Not sure what else to offer currently, ... maybe turning on DB logging and seeing what queries are being run... or double checking the relationship...
Hope that helps.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community