*/ 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; } } }