Skip to content

Error on multiple deletion when permission does not allow one of it #181

@martinsoenen

Description

@martinsoenen

Laravel Rest Api Version

2.14.2

Laravel Version

12.20.0

PHP Version

8.3.7

Database Driver & Version

No response

Description

When you want to delete multiple items, if one of the items is not authorised for deletion, the query returns an error, but the previous items in the query are still deleted.
Surely it would be possible to set up a transaction?

Steps To Reproduce

  • Create a model with at least 3 elements
  • Create a policy that doesn't permit to delete the element with id 2
<?php

namespace App\Policies;

use App\Models\Car;

class CarPolicy
{
    public function delete(User $user, Car $car): bool
    {
        if ($car->id === 2)
            return false;
        else
            return true;
    }
}
  • Try to delete the elements 1, 2 and 3 using REST API

URL : {{api}}/cars
Method : DELETE

{
  "resources" : [1, 2, 3]
}

The answer will be that it is forbidden, but the car with id 1 has been deleted well. It seems it iterates for each deletion until there is a problem, where the process stops.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions