mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Prevent deleting accessory that has checkouts via api
This commit is contained in:
parent
00cbebd1e3
commit
a19582a5f3
|
@ -249,11 +249,11 @@ class AccessoriesController extends Controller
|
|||
public function destroy($id)
|
||||
{
|
||||
$this->authorize('delete', Accessory::class);
|
||||
$accessory = Accessory::findOrFail($id);
|
||||
$accessory = Accessory::withCount('checkouts as checkouts_count')->findOrFail($id);
|
||||
$this->authorize($accessory);
|
||||
|
||||
if ($accessory->hasUsers() > 0) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.assoc_users', ['count'=> $accessory->hasUsers()])));
|
||||
if ($accessory->checkouts_count > 0) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.assoc_checkouts', ['count' => $accessory->checkouts_count])));
|
||||
}
|
||||
|
||||
$accessory->delete();
|
||||
|
|
Loading…
Reference in a new issue