json(LoanOrderIndexResource::collection( LoanOrder::query() ->where('user_id', auth()->id()) ->where('source', OrderRepo::MOBILE_DEVICE) ->paginate() )); } /** * SAVE* Loan order. * * `Karz sargytlary save`. Example bar, online panelkadan gorup hem bilersin. Update store daky yaly, yone oz ugratyan zadyn update bolyar, eger ugratmasaň, üýtgemez. */ public function store(LoanOrderStoreRequest $request, LoanOrder $loanOrder): JsonResponse { Log::channel('form_logs')->info('loan-order-update-request', $request->all()); $data = $request->validated(); $months = DateHelperRepository::monthsAsNumber(); $years = DateHelperRepository::yearsUntil(); if ($request->filled('card_month')) { $data['card_month'] = indexByValue($request->card_month, $months); } if ($request->filled('card_year')) { $data['card_year'] = indexByValue($request->card_year, $years); } if ($request->filled('guarantor_card_month')) { $data['guarantor_card_month'] = indexByValue($request->guarantor_card_month, $months); } if ($request->filled('guarantor_card_year')) { $data['guarantor_card_year'] = indexByValue($request->guarantor_card_year, $years); } if ($request->filled('guarantor_2_card_month')) { $data['guarantor_2_card_month'] = indexByValue($request->guarantor_2_card_month, $months); } if ($request->filled('guarantor_2_card_year')) { $data['guarantor_2_card_year'] = indexByValue($request->guarantor_2_card_year, $years); } $data += $this->uploadedFiles($request); Model::unguarded(function () use ($loanOrder, $data) { $loanOrder->update($data); }); return response()->json([ 'message' => __('Successfully updates'), ]); } /** * Upload files * * @return array */ public function uploadedFiles(Request $request): array { $files = []; foreach (['passport_one', 'passport_two', 'passport_three', 'passport_four'] as $field) { if ($request->hasFile($field)) { $files[$field] = Str::after($request->file($field)->store('public'), 'public/'); } } return $files; } /** * SHOW* Loan order * * `Karz sargytlary show by id`. ID ugradyp alyan route -da. Base App Enum-lardan peydalan. Panelkadan gor. */ public function show(LoanOrder $loanOrder): JsonResponse { if ($loanOrder->user_id != auth()->id()) { return response()->json(status: 403); } return response()->json(new LoanOrderShowResource($loanOrder)); } /** * Update the specified resource in storage. * * `Karz sargytlary update`. ID ugradyp `route`-da update edip bilyan. Base App Enum-lardan peydalan. Panelkadan gor. */ public function update(Request $request): void { // } /** * DELETE* loan order resource */ public function destroy(LoanOrder $loanOrder): JsonResponse { if ($loanOrder->user_id === auth()->id()) { return response()->json(status: 403); } $loanOrder->delete(); return response()->json(); } }