Answer the question
In order to leave comments, you need to log in
How to correctly add record to related tables laravel?
I looked at the manuals, but it’s a bit different from what I need
. I have 2 entities (post and categories) one-to-many relationship
in the code, there may be errors because I write about the method
in the request, an array with category id comes
$post = new Post();
$post->fill($request->validate());
$post->save();
foreach($request->query('categories') as $cat){
$categories = Categories::find($cat);
$categoris->post_id = $post->id;
$categoies->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