72 lines
1.6 KiB
PHP
Executable File
72 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\AiProvider;
|
|
use Illuminate\Support\Facades\Log;
|
|
use RuntimeException;
|
|
|
|
class AiProviderService
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function index(): array
|
|
{
|
|
$paginator = AiProvider::with('models')
|
|
->latest()
|
|
->paginate(15);
|
|
|
|
return [
|
|
'data' => $paginator->items(),
|
|
'total' => $paginator->total(),
|
|
'per_page' => $paginator->perPage(),
|
|
'current_page' => $paginator->currentPage(),
|
|
'last_page' => $paginator->lastPage(),
|
|
'from' => $paginator->firstItem(),
|
|
'to' => $paginator->lastItem(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(array $data): AiProvider
|
|
{
|
|
return AiProvider::withTrashed()->firstOrCreate(
|
|
['slug' => $data['slug']],
|
|
$data
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(AiProvider $provider, array $data): AiProvider
|
|
{
|
|
$provider->update($data);
|
|
|
|
return $provider;
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(AiProvider $provider): bool
|
|
{
|
|
try {
|
|
$provider->delete();
|
|
|
|
return true;
|
|
} catch (RuntimeException $e) {
|
|
Log::error('Failed to delete AI provider: ' . $e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|