diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 83915905b3..59ef32e617 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -5,7 +5,9 @@ namespace App\Http\Controllers\Api; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Http\Transformers\LicensesTransformer; +use App\Http\Transformers\LicenseSeatsTransformer; use App\Models\License; +use App\Models\LicenseSeat; use App\Models\Company; class LicensesController extends Controller @@ -162,4 +164,38 @@ class LicensesController extends Controller { // } + + /** + * Get license seat listing + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @param int $licenseId + * @return \Illuminate\Contracts\View\View + */ + public function seats(Request $request, $licenseId) + { + + if ($license = License::find($licenseId)) { + + $seats = LicenseSeat::where('license_id', $licenseId)->with('license', 'user', 'asset'); + + $offset = request('offset', 0); + $limit = request('limit', 50); + $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; + + $total = $seats->count(); + $seats = $seats->skip($offset)->take($limit)->get(); + + if ($seats) { + return (new LicenseSeatsTransformer)->transformLicenseSeats($seats, $total); + } + + } + + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/licenses/message.does_not_exist')), 200); + + } + + }