From c930c2658938b93563a1fda06d789c0656bf1561 Mon Sep 17 00:00:00 2001 From: AmirmahdiNourkazemi Date: Wed, 3 Jun 2026 16:28:49 +0330 Subject: [PATCH] feat: chat topic added --- app/Http/Controllers/ChatTopicController.php | 70 +++++++++++++++++++ app/Models/ChatTopic.php | 15 ++++ ..._06_03_120000_create_chat_topics_table.php | 31 ++++++++ routes/api.php | 5 ++ 4 files changed, 121 insertions(+) create mode 100644 app/Http/Controllers/ChatTopicController.php create mode 100644 app/Models/ChatTopic.php create mode 100644 database/migrations/2026_06_03_120000_create_chat_topics_table.php diff --git a/app/Http/Controllers/ChatTopicController.php b/app/Http/Controllers/ChatTopicController.php new file mode 100644 index 0000000..5020805 --- /dev/null +++ b/app/Http/Controllers/ChatTopicController.php @@ -0,0 +1,70 @@ +boolean('include_inactive')) { + $query->where('is_active', true); + } + + return response()->json($query->orderBy('order')->get()); + } + + public function show($id) + { + return response()->json(ChatTopic::findOrFail($id)); + } + + public function store(Request $request) + { + $data = $request->validate([ + 'title' => 'required|string|max:255', + 'description' => 'nullable|string', + 'order' => 'nullable|integer', + 'is_active' => 'nullable|boolean', + ]); + + $topic = ChatTopic::create($data); + + return response()->json([ + 'message' => 'Topic created successfully', + 'topic' => $topic, + ], 201); + } + + public function update(Request $request, $id) + { + $topic = ChatTopic::findOrFail($id); + + $data = $request->validate([ + 'title' => 'sometimes|string|max:255', + 'description' => 'nullable|string', + 'order' => 'nullable|integer', + 'is_active' => 'nullable|boolean', + ]); + + $topic->update($data); + + return response()->json([ + 'message' => 'Topic updated successfully', + 'topic' => $topic, + ]); + } + + public function destroy($id) + { + $topic = ChatTopic::findOrFail($id); + $topic->delete(); + + return response()->json(['message' => 'Topic deleted successfully']); + } +} diff --git a/app/Models/ChatTopic.php b/app/Models/ChatTopic.php new file mode 100644 index 0000000..69ba436 --- /dev/null +++ b/app/Models/ChatTopic.php @@ -0,0 +1,15 @@ + 'boolean', + 'order' => 'integer', + ]; +} diff --git a/database/migrations/2026_06_03_120000_create_chat_topics_table.php b/database/migrations/2026_06_03_120000_create_chat_topics_table.php new file mode 100644 index 0000000..94c3d1a --- /dev/null +++ b/database/migrations/2026_06_03_120000_create_chat_topics_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('title'); // chip text shown in the advisor chat + $table->text('description')->nullable(); + $table->integer('order')->default(0); + $table->boolean('is_active')->default(true); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('chat_topics'); + } +}; diff --git a/routes/api.php b/routes/api.php index ae354ed..e1360b6 100644 --- a/routes/api.php +++ b/routes/api.php @@ -12,6 +12,7 @@ use Illuminate\Support\Facades\Hash; use App\Http\Controllers\QuestionController; use App\Http\Controllers\SurveyQuestionController; +use App\Http\Controllers\ChatTopicController; use App\Http\Controllers\SliderController; use App\Http\Controllers\SceneController; use App\Http\Controllers\BellSoundController; @@ -121,6 +122,10 @@ Route::delete('/questions/{question}', [QuestionController::class, 'destroy']); + /// advisor chat — suggested topics (موضوعات پیشنهادی) + Route::apiResource('chat-topics', ChatTopicController::class); + + /// survey questions feature (question + description + single/multi options, answered by users) // Admin: see all users' answers (must be registered before the resource so it isn't caught by {survey_question}). Route::middleware('abilities:admin')->group(function () {