Answer the question
In order to leave comments, you need to log in
Laravel 5. How to correctly insert the id of the current insert into a table cell?
Good to everyone!
When adding a record to the table, you must insert the id of the current record into one of the cells. Is it possible to do this in one request? I have several options, but I do not know if they are correct.
Option 1:
$insert = Post::create([
'name' => 'name',
'text' => 'text'
]);
$post = Post::find($insert->id);
$post->name( $post->name . $insert->id);
$post->save();
$post = new Post();
$post->save();
$arr = array(
'name' => 'name' . $post->id,
'text' => 'text'
);
$post->fill($arr);
$post->save();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question