latest('id') ->paginate($this->limit()); return response()->json($batches); } public function show(ImportBatch $importBatch) { return response()->json($importBatch->load('store.channel')); } public function store(Request $request) { if (! Storage::disk('uploads')->exists($request->input('source_file'))) { return $this->errorBadRequest('The source file does not exist in the private uploads storage.'); } try { $batch = ImportBatch::create(array_merge($request->validated(), [ 'company_id' => company_id(), 'status' => 'queued', 'created_by' => user_id(), 'created_from' => 'ecommerce-finance', ])); } catch (QueryException $exception) { return $this->errorBadRequest('An identical import batch has already been created.'); } $this->dispatch(new ProcessImportBatch($batch->id)); $batch->refresh(); return response() ->json($batch, 201) ->header('Location', route('api.ecommerce-finance.import-batches.show', $batch)); } private function limit(): int { return min(max((int) request('limit', 25), 1), 100); } }