Fixed 1001 query on license

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-09-19 16:04:54 +01:00
parent 7650628d30
commit 634a4afa75
2 changed files with 2 additions and 2 deletions

View file

@ -182,7 +182,7 @@ class LicensesController extends Controller
public function show($id) : JsonResponse | array public function show($id) : JsonResponse | array
{ {
$this->authorize('view', License::class); $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'); $license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset');
return (new LicensesTransformer)->transformLicense($license); return (new LicensesTransformer)->transformLicense($license);

View file

@ -61,7 +61,7 @@ class LicensesTransformer
'checkin' => Gate::allows('checkin', License::class), 'checkin' => Gate::allows('checkin', License::class),
'clone' => Gate::allows('create', License::class), 'clone' => Gate::allows('create', License::class),
'update' => Gate::allows('update', 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; $array += $permissions_array;