'Retrieved Model Attributes for Admin Workflow ', 'message' => 'You have successfully retrieved Model Attributes for Admin Workflow' ]; } /** @var CanFetchQuestion */ private $canFetchQuestion; /** @var FetchesBooking */ private $fetchesBooking; /** * FetchAdminWFModelAttributesLogic constructor. * @param CanFetchQuestion $canFetchQuestion * @param FetchesBooking $fetchesBooking */ public function __construct(CanFetchQuestion $canFetchQuestion, FetchesBooking $fetchesBooking) { $this->canFetchQuestion = $canFetchQuestion; $this->fetchesBooking = $fetchesBooking; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { $this->canFetchQuestion->passes(); // $booking = Booking::find($request->route('booking_id')); $booking = $this->fetchesBooking->execute(['id' => $request->route('booking_id'), 'with_transactions' => true, 'order_by_id_desc' => true]); if (!$booking) { return responseJson(null, 'No booking found', 404); } $attributes = $booking->modelAttributes() ->where('name', BookingAttributeNames::ORDER_REFERENCE_NO) ->get(['id', 'value']) ->map(fn ($attr) => $attr->only(['id', 'value'])); $transaction = $booking->bills()->first(); //cief todo: 74 - more than 1 record? // return responseJson([ // 'booking' => $booking, // 'booking_attributes' => $attributes, // 'reference' =>$transaction->owner->owner->marking, // 'marking' => $transaction->owner->owner->company->reference, // 'currency_rate' => $transaction->currency_rate, // 'total_amount' =>$transaction->currency->short_code . ' ' . number_format((float)$transaction->amount, 2, '.', '') // ]); return $this->resourceResponse(new BookingBaseResource($booking)); } }