First Commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user