71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\PromptTemplate;
|
|
use Illuminate\Support\Facades\Log;
|
|
use RuntimeException;
|
|
|
|
class PromptTemplateService
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function index(): array
|
|
{
|
|
$paginator = PromptTemplate::with('user')
|
|
->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): PromptTemplate
|
|
{
|
|
$data['user_id'] = auth()->id();
|
|
|
|
return PromptTemplate::create($data);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(PromptTemplate $template, array $data): PromptTemplate
|
|
{
|
|
$template->update($data);
|
|
|
|
return $template;
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(PromptTemplate $template): bool
|
|
{
|
|
try {
|
|
$template->delete();
|
|
|
|
return true;
|
|
} catch (RuntimeException $e) {
|
|
Log::error('Failed to delete prompt template: ' . $e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|