has('limit')) { $perPage = $request->limit; } $contact = Auth::guard('customer')->id(); $query = Estimate::with(['items', 'customer', 'taxes', 'creator']) ->where('status', '<>', Estimate::STATUS_DRAFT) ->whereCustomer($contact); $query->applyFilters($request->only([ 'status', 'estimate_number', 'from_date', 'to_date', 'orderByField', 'orderBy', ])); $page = $query->latest()->paginateData($perPage); $visible = Estimate::query() ->where('status', '<>', Estimate::STATUS_DRAFT) ->whereCustomer($contact) ->count(); return EstimateResource::collection($page) ->additional(['meta' => [ 'estimateTotalCount' => $visible, ]]); } /** * Hand back a single offer, looked up inside the portal's company and * narrowed to the signed-in contact so ids cannot be probed. * * @param string $id * @return Response */ public function show(Company $company, $id) { $contact = Auth::guard('customer')->id(); $estimate = $company->estimates()->whereCustomer($contact)->where('id', $id)->first(); if ($estimate === null) { return response()->json(['error' => 'estimate_not_found'], Response::HTTP_NOT_FOUND); } return EstimateResource::make($estimate); } }