Reputation: 107
I'm having a problem deleting a record from the database. I'm using InertiaJS & Laravel.
Component Code The following is the link/button code:
<Link class="trash" @click="submit(result.ChildID)">
Move to Trash
</Link>
Note : ChildID is the id of a child record in the database.
Now: When a user clicks this link, a method will be called, which is given below.
methods: {
submit: function (ChildID) {
alert(ChildID)
if (confirm("Are you sure you want to delete this child?")) {
this.$inertia.delete('destroy/ChildID');
}
},
},
Route Code
Route::delete('destroy/{childID}',[childrenController::class,'destroy']);
Controller Code
public function destroy(children $childID){
$childID->delete();
return redirect()->route('View_Child_Profile');
}
Now when I'm hitting the delete button, I'm getting the following error:
Upvotes: 1
Views: 1457
Reputation: 39
try this. I think you are doing mistake "this.$inertia.delete('destroy/ChildID');"
methods: {
submit: function (ChildID) {
alert(ChildID)
if (confirm("Are you sure you want to delete this child?")) {
this.$inertia.delete(`destroy/${ChildID}`);
// or
this.$inertia.delete('destroy/'+ChildID);
}
},
},
Upvotes: 2
Reputation: 379
Here is how I handle delete process .
Front Vue + Inertia:
import { Link } from '@inertiajs/inertia-vue3';
In Template :
<Link method="delete" :href="route('admin.insta_feeds.destroy',id)">Delete</Link>
Back End Laravel:
Route :
Route::resource('insta_feeds', InstaFeedsController::class);
Controller Function :
public function destroy(InstaFeed $insta_feed)
{
if(isset($insta_feed->image_path)){
Storage::delete($insta_feed->image_path);
}
$insta_feed->delete();
return Redirect::route('admin.insta_feeds.index');
}
Upvotes: 0