opnform/app/Http/Controllers/Forms/AiFormController.php

35 lines
982 B
PHP
Raw Normal View History

2023-03-26 10:54:12 +00:00
<?php
namespace App\Http\Controllers\Forms;
use App\Http\Controllers\Controller;
use App\Http\Requests\AiGenerateFormRequest;
use App\Models\Forms\AI\AiFormCompletion;
2023-03-26 10:54:12 +00:00
class AiFormController extends Controller
{
public function generateForm(AiGenerateFormRequest $request)
{
$this->middleware('throttle:4,1');
return $this->success([
'message' => 'We\'re working on your form, please wait ~1 min.',
'ai_form_completion_id' => AiFormCompletion::create([
'form_prompt' => $request->input('form_prompt'),
2024-02-23 10:54:12 +00:00
'ip' => $request->ip(),
])->id,
2023-03-26 10:54:12 +00:00
]);
}
public function show(AiFormCompletion $aiFormCompletion)
2023-03-26 10:54:12 +00:00
{
if ($aiFormCompletion->ip != request()->ip()) {
return $this->error('You are not authorized to view this AI completion.', 403);
2023-03-26 10:54:12 +00:00
}
return $this->success([
2024-02-23 10:54:12 +00:00
'ai_form_completion' => $aiFormCompletion,
]);
2023-03-26 10:54:12 +00:00
}
}