How do i delete one row in my SQLite table?

67 Views Asked by At

I'm trying to delete one row of data from my sql table called "cart". It seems to me that it can not find the id called "cartid". im using a program called insomnia and it wont take my input it feels like.

it is gettting a error that is called :"MethodNotAllowedHttpException"

im using laravel 5.4, it is a requirement for me.

i have other functions that work and i do not understand why this one does not.

https://i.stack.imgur.com/YKikW.jpg

some snapshots from my code

i have tried to use

Route::delete('cart-remove/{id}', 'CartController@delete');

and alot more

this is in my 'api.php' file:

Route::delete('cart-remove', 'CartController@delete');

this is in my file called 'CartController':

class CartController extends Controller {

    public function delete($id) {

        DB::table('cart')->where('cartid', '=', $id)->delete();

        return response($id, 200);


    }
}

i want to get the id from my program called 'insomnia' to remove that id in my sqlite database.

1

There are 1 best solutions below

0
rkg On

Use the model's destroy method when deleting entries from the database:

use App\SomeModel;

class SomeController extends Controller {
    public function destroy($id) //or delete($id)
    {
         SomeModel::destroy($id);
         return response($id, 200);
    }
}