pHaider
4 days ago
107
6
Laravel

explode() expects parameter 2 to be string, array given

Posted 4 days ago by pHaider

Hello everyone,

I'm a newbie with Laravel and Vue, I have a tagging feature with my system and facing a problem with saving the tags!

I'm using this framework for Laravel tag: https://github.com/spatie/laravel-tags and this framework for Vue input: https://github.com/voerro/vue-tagsinput

For more, I'm following this tutorial to apply the tagging system: https://medium.com/js-dojo/laravel-tags-input-with-autocomplete-using-vuejs-4fceca99b86e

this is my Vue code:

<tags-input class="block w-full" v-model="form.tags" element-id="tags" typeahead-style="badges" :add-tags-on-comma="true" :allow-duplicates="true" :typeahead="true" :existing-tags="existingTags"> </tags-input>

submit() { axios.post('/costs/tags', this.form) .then(response => { alert('added'); }).catch(error => { this.error = error.response.data.message; alert(this.error); }); }

This is my Back-end code:

public function tags(Request $request) { $floor = Floor::find(1);

    $tags = explode(",", $request->tags);
    $floor->attachTags($tags);

}

Please sign in or create an account to participate in this conversation.