@rod2rick I think you really need to look at breaking your components down; they’re far too big.
I don’t really know what it is you’re asking, and not going to comb through two massive chunks of code.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I would like to set up a CRUD, in Laravel and so far the Create, Read and Delete have worked fine. I get the error Error: Request failed with status code 500 when i want to update the product element.
Here is my code: 1- my update code in vue
updateProduit() {
// alert (this.id);
const config = {
headers: {
"content-type": "multipart/form-data",
"X-CSRF-TOKEN": document.querySelector('meta[name="csrf-token"]')
.content,
},
};
axios.put("/api/updateProduit/" + this.id, config, {
id : this.id,
nom : this.nom,
description : this.description,
prix : this.prix,
type : this.type,
image : this.image,
categories_id : this.categories_id
})
// .then(response => {
// this.form.reset();
// window.location = response.data.redirect;
// })
// .then(location.reload())
.catch(function (error) {
console.log(error);
})
},
the controller
// update product
public function updateProduit(Request $request, $id)
{
$produit = Produits::find($id);
$produit->id = $request->id;
$produit->nom = $request->nom;
$produit->description = $request->description;
$produit->prix = $request->prix;
$produit->type = $request->type;
$produit->categories_id = $request->categories_id;
$produit->users_id = $request->users_id;
$produit->image = $request->image;
if ($request->hasfile('image')) {
$image = $request->file('image');
$originalName = $image->getClientOriginalName();
// $fileExtension = $image->getClientOriginalExtension();
$filename = $originalName;
if ($produit->image && $produit->image == 'noproductimage.jpg') {
Image::make($image)->resize(500, 500)->save(public_path('/uploads/produits/' . $filename));
} else {
File::delete(public_path('/uploads/produits/' . $produit->image));
Image::make($image)->resize(500, 500)->save(public_path('/uploads/produits/' . $filename));
}
$produit->image = $filename;
};
$produit->update();
return response()->json(['success' => 'Produit modifié avec succès']);
}
The route
Route::put('/updateProduit/{id}', [App\Http\Controllers\Api\ProduitController::class, 'updateProduit'])->name('updateProduit');
what did i do wrong, Please i need your help, For 3 weeks, I have stagnated in the same place.
Thanks in advance
I got the solution of my problem Here is the solution :
<template #cell(edit)="data">
<center>
<button class="btn btn-sm btn-outline-info"
v-on:click="editProduit(data.item.id)"
data-target="#modalEdit">
<i class="fas fa-pen"></i>
</button>
</center>
</template>
the script,
Get the product on the Modal
editProduit(id) {
axios
.get("/api/edit/" + id)
.then((response) => {
this.id = response.data.id;
this.nom = response.data.nom;
this.description = response.data.description;
this.prix = response.data.prix;
this.type = response.data.type;
this.image = response.data.image;
this.categories_id = response.data.categories_id;
this.fournisseurs_id = response.data.fournisseurs_id;
this.users_id = response.data.users_id;
this.$refs.myModalRefEdit.show();
})
.catch((error) => console.log(error));
},
The update method product on the Modal
updateProduit() {
const data = new FormData();
data.append("nom", this.nom);
data.append("description", this.description);
data.append("prix", this.prix);
data.append("type", this.type);
data.append("image", this.image);
data.append("categories_id", this.categories_id);
data.append("fournisseurs_id", this.fournisseurs_id);
data.append("users_id", this.users_id);
const config = {
headers: {
"content-type": "multipart/form-data",
"X-CSRF-TOKEN": document.querySelector('meta[name="csrf-token"]')
.content,
},
};
axios
.post("/api/updateProduit/" + this.id, data, config)
.then((response) => {
this.form.reset();
window.location = response.data.redirect;
})
.then(location.reload())
.catch(function (error) {
console.log(error);
});
},
Please or to participate in this conversation.