```php aiService = $aiService; $this->ocrService = $ocrService; } public function question(Request $request) { $request->validate([ 'question' => 'required|string', 'document_id' => 'required|integer|exists:documents,id' ]); $document = Document::findOrFail($request->document_id); // Check user permissions if (!auth()->user()->canAccessDocument($document)) { return response()->json(['error' => 'Accès non autorisé'], 403); } // Extract text from document $text = $this->ocrService->extractText($document->file_path); // Get AI response $response = $this->aiService->askQuestion($request->question, $text, $document->id); // Log the interaction $this->logInteraction(auth()->id(), $document->id, $request->question, $response); return response()->json([ 'response' => $response, 'document' => $document->name ]); } protected function logInteraction($userId, $documentId, $question, $response) { \DB::table('assistant_logs')->insert([ 'user_id' => $userId, 'document_id' => $documentId, 'question' => $question, 'response' => $response, 'created_at' => now(), 'updated_at' => now() ]); } } ``` ```