diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 581a23a36..de43926b7 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -182,7 +182,7 @@ class LicensesController extends Controller public function show($id) : JsonResponse | array { $this->authorize('view', License::class); - $license = License::withCount('freeSeats')->findOrFail($id); + $license = License::withCount('freeSeats as free_seats_count')->findOrFail($id); $license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset'); return (new LicensesTransformer)->transformLicense($license); diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.php index b30b60301..06eb17290 100644 --- a/app/Http/Transformers/LicensesTransformer.php +++ b/app/Http/Transformers/LicensesTransformer.php @@ -61,7 +61,7 @@ class LicensesTransformer 'checkin' => Gate::allows('checkin', License::class), 'clone' => Gate::allows('create', License::class), 'update' => Gate::allows('update', License::class), - 'delete' => (Gate::allows('delete', License::class) && ($license->seats == $license->availCount()->count())) ? true : false, + 'delete' => (Gate::allows('delete', License::class) && ($license->free_seat_count > 0)) ? true : false, ]; $array += $permissions_array;