Skip to content
Advertisement

Laravel PUT relationship

Fiddling with Laravel and coming from Symfony, I’m trying to replicate some code. I’m trying to PUT a Suggestion model (overwritting anything, even relationships) and wanted to know the proper way to overwrite the model. Since tags attribute in fillable doesn’t exist, I certainly get an error (Undefined column: 7 ERROR: column "tags" of relation "suggestions" does not exist). Suggestions and tags both have their own tables and a pivot table that contains two foreign keys to both tables id.

Request & Response :

JavaScript
JavaScript
JavaScript

Advertisement

Answer

You could just pass an array of IDs for tags instead of the whole object.

Do:

JavaScript

Instead of:

JavaScript

Change the validation rules accordingly and then you can remove tags from $fillable and do something like:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement