[英]how to delete multiple records from database ( using laravel 5.5)
I am trying to delete multiple records from database but I am currently unable to do that.我正在尝试从数据库中删除多条记录,但我目前无法这样做。 I can only delete first record from the database and I am using postman for my request.
我只能从数据库中删除第一条记录,并且我正在使用邮递员来处理我的请求。
My Code:我的代码:
Route::post('delete_page',function(Request $request) {
$all_data = $request->all();
foreach($all_data as $id) {
\App\Page::where('id',$id)->delete();
}
});
I am passing my value from postman like this: form-data:我像这样从邮递员那里传递我的价值:表单数据:
key is: array[id] and value is any id that is 3
key is: array[id] and value is any id that is 4
If I hit my request it only deletes the record with id 3, but I want to delete multiple records.如果我满足我的请求,它只会删除 ID 为 3 的记录,但我想删除多条记录。 How can I do that?
我怎样才能做到这一点?
Your help will be highly appreciated!您的帮助将不胜感激!
Try this尝试这个
$ids = [1, 2, 3, 4]; $ids = [1, 2, 3, 4];
\\App\\Page:: whereIn('id',$ids)->delete(); \\App\\Page:: whereIn('id',$ids)->delete();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.