protectedfunctionfields(){return [Tags::make('Tags')//The field expects a comma separated array.->default($this->model->exists ?$this->model->tags()->pluck('name'): [])->relation()//save the items with saveFoo() hook, se below->deferEntangle(false);//->errorMsg(...)->help(...)->placeholder(...) //default in translation files//->rules(...); //applied to each tag, default = 'string|alpha_num|between:3,25' ];}
Save the tags
If your tags are a relationship, you probably want to save the data manually.
protectedfunctionsaveTags($validated_array){//example; remove duplicates, ucfirst on each array item $cleaned =array_map('ucfirst', array_unique($validated_array));//Spatie sync tags$this->model->syncTags($cleaned);}