Laravelde yazdığım APİ Vue 3 te kayıt ederken vue de tagı yakalayamıyorum yazsamda hiç bir şey yazmamışım gibi input algılamıyor. Laravelde Taggable paketini kullanıyorum
Model
class Portfolio extends Model
{
use HasFactory;
use \Conner\Tagging\Taggable;
protected $fillable = ['title', 'description', 'url', 'tags'];
}
Controller
public function store(PortfolioRequest $request)
{
$portfolio = Portfolio::create($request->validated());
$tags = explode(",", $request->tags);
$portfolio->tag($tags);
return new PortfolioResource($portfolio);
}
Vue
<div class="form-group">
<label for="example-price-input">Taq</label>
<br />
<input type="text" id="example-price-input" data-role="tagsinput" name="tags" placeholder="Taq Daxil Edin..." v-model="form.tags" />
<div v-if="errors && errors.tags" class="bg-red">
<small style="color:red">{{ errors.tags[0] }}</small>
</div>
</div>
<script setup>
import { ref } from "vue";
import axiosClient from "../../axiosClient.js";
const form = ref({
'title' : '',
'description' : '',
'url' : '',
'tags' : []
});
const errors = ref("");
const success = ref(false);
const savePortfolio = async () => {
try {
const formdata = new FormData();
formdata.append('title',form.value.title)
formdata.append('description',form.value.description)
formdata.append('url',form.value.url)
formdata.append('tags',form.value.tags)
let config =
{ headers: {
'Content-Type': "multipart/form-data; charset=utf-8; boundary=" + Math.random().toString().substr(2)
} }
await axiosClient.post("portfolios",formdata,config)
success.value = true
form.value.title = ''
form.description = ''
form.value.tags = ''
form.value.url = ''
} catch(error) {
if(error.response.status === 422) {
errors.value = error.response.data.errors;
}
errors.value = error.response.data.errors;
}
}
</script>
<style scoped>
.bootstrap-tagsinput .tag {
margin-right: 2px;
color: #ffffff;
background: #2196f3;
padding: 3px 7px;
border-radius: 3px;
}
.bootstrap-tagsinput {
width: 100%;
}
</style>