answers($request->all()); // Comparisons already kept in the investor's own dossiers, to resume them from the general page. $contexts = $request->user() ? collect(app(InvestorPath::class)->contexts($request->user())) : collect(); $kept = $contexts->isEmpty() ? collect() : DB::table('desk_events')->whereIn('case_id', $contexts->pluck('id')) ->where('action', CompanyComparison::EVENT)->selectRaw('case_id, max(created_at) as at')->groupBy('case_id')->pluck('at', 'case_id'); $data = ['definition' => $service->definition(), 'answers' => $answers, 'result' => $service->evaluate($answers), 'case' => null, 'saved' => null, 'canWrite' => false, 'history' => [], 'historyNext' => null, 'historical' => false, 'workingCopy' => false, 'savedCases' => $contexts->filter(fn (array $c) => $kept->has($c['id'])) ->map(fn (array $c) => ['id' => $c['id'], 'title' => $c['title'], 'at' => (string) $kept[$c['id']]])->values()->all()]; return $request->expectsJson() ? response()->json($data) : Inertia::render('investment/company-comparison', $data); } public function show(Request $request, string $id, CompanyComparison $service): Response|JsonResponse { $data = ['definition' => $service->definition(), ...$service->view($request->user(), $id, $request->all())]; return $request->expectsJson() ? response()->json($data) : Inertia::render('investment/company-comparison', $data); } public function save(Request $request, string $id, CompanyComparison $service): JsonResponse { return response()->json($service->save($request->user(), $id, $request->all())); } }