I have pivot table post_tags
which will store id of post and id of tag
PS:
all my tables using uuid
.
Now when I try to add/change my post tags in update function it returns this error:
message: "SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'tag_id' at row 1 (SQL: insert into `post_tags` (`id`, `post_id`, `tag_id`) values (d0fb529e-38ac-4197-9455-e41898de9d05, c4a41a90-1274-4830-8974-71d6b5834216, bd89cf45-bb85-4e4b-93f8-342e86dbaa31,9adc54df-e778-432d-be25-282169a7c5af))"
//.....
$post->save();
$tags_id = (array) $request->input('tags');
foreach( $tags_id as $tag_id ) {
$tag_data_to_sync[ $tag_id ] = [ 'id' => \Ramsey\Uuid\Uuid::uuid4()->toString() ];
}
$post->tags()->sync( $tag_data_to_sync );
Any idea?
My tags ids came like "86198680-1f0b-4544-851a-4c39e4f7c3ec,2bbe9776-7413-43fa-9cae-3378f39f3c2d"
and I had to explode my tags data in order to loop them
$tags_id = explode(',', $request->input('tags'));
Now works just fine.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments