mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
First stab at handling the n+1 issue on licenses
This commit is contained in:
parent
f47075c180
commit
368ac5b85d
|
@ -21,7 +21,7 @@ class LicensesController extends Controller
|
|||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('view', License::class);
|
||||
$licenses = Company::scopeCompanyables(License::with('company', 'licenseSeatsRelation', 'manufacturer', 'supplier'));
|
||||
$licenses = Company::scopeCompanyables(License::with('company', 'licenseseats', 'manufacturer', 'supplier')->withCount('licenseseats'));
|
||||
|
||||
if ($request->has('search')) {
|
||||
$licenses = $licenses->TextSearch($request->input('search'));
|
||||
|
|
|
@ -33,16 +33,14 @@ class LicensesTransformer
|
|||
'notes' => e($license->notes),
|
||||
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
|
||||
'total_seats' => (int) $license->seats,
|
||||
'next_seat' => ($license->freeSeat()) ? (int) $license->freeSeat()->id : null,
|
||||
'remaining_qty' => (int) $license->remaincount(),
|
||||
'min_qty' => $license->remaincount(),
|
||||
'remaining_qty' => (int) ($license->seats - $license->licenseseats_count),
|
||||
'license_name' => e($license->license_name),
|
||||
'license_email' => e($license->license_email),
|
||||
'maintained' => ($license->maintained == 1) ? true : false,
|
||||
'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id,'name'=> e($license->supplier->name)] : null,
|
||||
'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'),
|
||||
'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),
|
||||
'user_can_checkout' => (bool) ($license->remaincount() > 0),
|
||||
'user_can_checkout' => (bool) (($license->seats - $license->licenseseats_count) > 0),
|
||||
];
|
||||
|
||||
$permissions_array['available_actions'] = [
|
||||
|
|
Loading…
Reference in a new issue