简体   繁体   English

如何删除SQLite表中的一行?

[英]How do i delete one row in my SQLite table?

I'm trying to delete one row of data from my sql table called "cart". 我正在尝试从名为“购物车”的sql表中删除一行数据。 It seems to me that it can not find the id called "cartid". 在我看来,它找不到名为“ cartid”的ID。 im using a program called insomnia and it wont take my input it feels like. 即时通讯使用一个名为失眠的程序,它不会占用我的感觉。

it is gettting a error that is called :"MethodNotAllowedHttpException" 它得到了一个错误,它称为:“ MethodNotAllowedHttpException”

im using laravel 5.4, it is a requirement for me. 我使用laravel 5.4,这是我的要求。

i have other functions that work and i do not understand why this one does not. 我还有其他起作用的功能,但我不明白为什么这个功能不起作用。

https://imgur.com/a/T0aOwJF https://imgur.com/a/T0aOwJF

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: 这是在我的“ api.php”文件中:

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

this is in my file called 'CartController': 这是在我名为“ 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. 我想从名为“失眠”的程序中获取ID,以在我的sqlite数据库中删除该ID。

Use the model's destroy method when deleting entries from the database: 从数据库删除条目时,请使用模型的destroy方法:

use App\SomeModel;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM