105 lines
2.8 KiB
PHP
Executable File
105 lines
2.8 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\AiProvider;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\AiProvider\StoreAiProviderRequest;
|
|
use App\Http\Requests\AiProvider\UpdateAiProviderRequest;
|
|
use App\Services\AiProviderService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\View\View;
|
|
|
|
class AiProviderController extends Controller
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*/
|
|
public function __construct(
|
|
private readonly AiProviderService $aiProviderService
|
|
) {}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(): View
|
|
{
|
|
$this->authorize('viewAny', \App\Models\AiProvider::class);
|
|
|
|
$result = $this->aiProviderService->index();
|
|
$providers = $result['data'] ?? [];
|
|
|
|
return view('ai-providers.index', compact('providers'));
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(\App\Models\AiProvider $aiProvider): View
|
|
{
|
|
$this->authorize('view', $aiProvider);
|
|
|
|
return view('ai-providers.show', compact('aiProvider'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create(): View
|
|
{
|
|
$this->authorize('create', \App\Models\AiProvider::class);
|
|
|
|
return view('ai-providers.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(StoreAiProviderRequest $request): RedirectResponse
|
|
{
|
|
$this->authorize('create', \App\Models\AiProvider::class);
|
|
|
|
$this->aiProviderService->store($request->validated());
|
|
|
|
return redirect()->route('ai-providers.index')
|
|
->with('success', 'Provider created successfully.');
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(\App\Models\AiProvider $aiProvider): View
|
|
{
|
|
$this->authorize('update', $aiProvider);
|
|
|
|
return view('ai-providers.edit', compact('aiProvider'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(UpdateAiProviderRequest $request, \App\Models\AiProvider $aiProvider): RedirectResponse
|
|
{
|
|
$this->authorize('update', $aiProvider);
|
|
|
|
$this->aiProviderService->update($aiProvider, $request->validated());
|
|
|
|
return redirect()->route('ai-providers.index')
|
|
->with('success', 'Provider updated successfully.');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(\App\Models\AiProvider $aiProvider): RedirectResponse
|
|
{
|
|
$this->authorize('delete', $aiProvider);
|
|
|
|
$this->aiProviderService->destroy($aiProvider);
|
|
|
|
return redirect()->route('ai-providers.index')
|
|
->with('success', 'Provider deleted successfully.');
|
|
}
|
|
}
|