Answer the question
In order to leave comments, you need to log in
How to implement normal insert into a table with relationships in laravel?
Hello.
There is a table with records (post) the post_support table is associated with it for relation to the support table.
I asked for the implementation idea here .
Schema::create('post_support', function (Blueprint $table) {
$table->increments('id');
$table->integer('post_id')->unsigned();
$table->integer('support_id');
$table->foreign('post_id')->references('id')->on('post');
});
public function supports() {
return $this->hasMany('App\PostSupport');
}
$post = App\Post::find($page_id);
foreach ($request->input('support_id') as $id) {
$post->supports()->save(
new App\PostSupport(['support_id' => $id])
);
}
if( DB::table('post')->where('id', '=', $page_id)->update($data) ) {
echo "ok";
}
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