cib88's avatar
Level 2

React & Inertia - Delete method for basic CRUD

I've got a basic CRUD on a project I'm building, but I seem to be having an issue with the delete method. My code somewhat works, if I click delete I get this error in the console

Uncaught (in promise) Error: Network Error
    at createError (app.js:708:15)
    at XMLHttpRequest.handleError

However if I refresh the the page the item is deleted.

I have this route Route::resource('admin/vertical-markets', VerticalMarketsController::class);

This is my delete method

public function destroy(VerticalMarket $VerticalMarket)
    {

        $verticalMarkets = VerticalMarket::select('id', 'name')->get();
        $VerticalMarket->delete();

        return Redirect::route('vertical-markets.index', ['verticalMarkets' => $verticalMarkets])->with('message', 'Vertical Market deleted');
    }

Ans this is how I'm handling it with react

const deleteRow = (id: number) => {
        Inertia.delete(`/admin/vertical-markets/${id}`);
    };
0 likes
0 replies

Please or to participate in this conversation.