Files
dockergprompt/app/Http/Controllers/PromptGeneration/PromptGenerationController.php
T
2026-09-01 09:22:30 -03:00

58 lines
1.6 KiB
PHP
Executable File

<?php
declare(strict_types=1);
namespace App\Http\Controllers\PromptGeneration;
use App\Http\Controllers\Controller;
use App\Http\Requests\PromptGeneration\GeneratePromptRequest;
use App\Models\PromptGeneration;
use App\Services\PromptGenerationService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class PromptGenerationController extends Controller
{
/**
* Create a new controller instance.
*/
public function __construct(
private readonly PromptGenerationService $promptGenerationService
) {}
/**
* Display a listing of prompt generations.
*/
public function index(): View
{
$generations = $this->promptGenerationService->index();
return view('prompt-generations.index', compact('generations'));
}
/**
* Generate a new prompt.
*/
public function generate(GeneratePromptRequest $request): RedirectResponse
{
$result = $this->promptGenerationService->generate($request->validated());
return redirect()->route('prompt-generations.index')
->with('success', 'Prompt generated successfully.')
->with('generation', $result);
}
/**
* Remove the specified prompt generation.
*/
public function destroy(Request $request, PromptGeneration $generation): RedirectResponse
{
$this->authorize('delete', $generation);
$this->promptGenerationService->destroy($generation);
return redirect()->back()->with('success', 'Prompt generation deleted successfully.');
}
}