Friday, May 4, 2018

how to delete multiple records from database ( using laravel 5.5) - development

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) {
        AppPage::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. How can I do that?

Your help will be highly appreciated!



from Laravel Questions and Answers https://laravelquestions.com/php/how-to-delete-multiple-records-from-database-using-laravel-5-5/
via Lzo Media

No comments:

Post a Comment