S
S
Semyon2017-08-01 20:07:13
Laravel
Semyon, 2017-08-01 20:07:13

How to remove a link from a table?

Hello! There are three tables: Post
table
posts
post_id
name
Category table
category
cat_id
name Link
table
post_category
post_id
cat_id
The view has a multiple list of categories for posts:

<select multiple="multiple" name="category[]">
<option value="1">Категория 1</option>
<option value="2">Категория 2</option>
<option value="3">Категория 3</option>
</select>

The documentation says that you need to use hasMany to save and display. All clear.
And how to delete records about categories that were removed from the post from the post_category table? I found about attach () and sync (), but did not understand if it is possible to do this through them and how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2017-08-01
@v_decadence

For such a connection, you need to use the BelongsToMany connection and use the two methods you specified.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question