First stab at handling the n+1 issue on licenses

This commit is contained in:
snipe 2017-11-02 18:20:42 -07:00
parent f47075c180
commit 368ac5b85d
2 changed files with 3 additions and 5 deletions

View file

@ -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'));

View file

@ -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'] = [