new chatgpt module for api intergration

This commit is contained in:
Mark Gregory
2026-06-24 09:56:13 +01:00
parent c5335dc635
commit a42b5787b9
28 changed files with 1028 additions and 107 deletions
@@ -3,77 +3,80 @@
namespace Modules\ChatGPT\Http\Controllers;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Controller;
use Modules\ChatGPT\Http\Requests\StoreChatGptApiSettingRequest;
use Modules\ChatGPT\Http\Requests\UpdateChatGptApiSettingRequest;
use Modules\ChatGPT\Models\ChatGptApiSetting;
class ChatGPTController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
* Display the ChatGPT module settings page.
*/
public function index()
public function index(): Renderable
{
return view('chatgpt::index');
return view('chatgpt::index', [
'settings' => ChatGptApiSetting::query()->latest('id')->get(),
]);
}
/**
* Show the form for creating a new resource.
* @return Renderable
* Store a new encrypted OpenAI API key setting.
*/
public function create()
public function store(StoreChatGptApiSettingRequest $request): RedirectResponse
{
return view('chatgpt::create');
$data = $request->validated();
ChatGptApiSetting::query()->update(['is_active' => false]);
ChatGptApiSetting::query()->create([
'name' => $data['name'] ?: 'OpenAI API Key',
'api_key' => $data['api_key'],
'is_active' => (bool) ($data['is_active'] ?? true),
]);
return redirect()
->route('chatgpt.index')
->with('status', 'OpenAI API key saved.');
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Renderable
* Update an encrypted OpenAI API key setting.
*/
public function store(Request $request)
public function update(UpdateChatGptApiSettingRequest $request, ChatGptApiSetting $setting): RedirectResponse
{
//
$data = $request->validated();
if ((bool) ($data['is_active'] ?? false)) {
ChatGptApiSetting::query()
->whereKeyNot($setting->getKey())
->update(['is_active' => false]);
}
$setting->name = $data['name'] ?: $setting->name;
$setting->is_active = (bool) ($data['is_active'] ?? false);
if (! empty($data['api_key'])) {
$setting->api_key = $data['api_key'];
}
$setting->save();
return redirect()
->route('chatgpt.index')
->with('status', 'OpenAI API key updated.');
}
/**
* Show the specified resource.
* @param int $id
* @return Renderable
* Delete an encrypted OpenAI API key setting.
*/
public function show($id)
public function destroy(ChatGptApiSetting $setting): RedirectResponse
{
return view('chatgpt::show');
}
$setting->delete();
/**
* Show the form for editing the specified resource.
* @param int $id
* @return Renderable
*/
public function edit($id)
{
return view('chatgpt::edit');
}
/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @return Renderable
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
* @param int $id
* @return Renderable
*/
public function destroy($id)
{
//
return redirect()
->route('chatgpt.index')
->with('status', 'OpenAI API key deleted.');
}
}