feat: chat topic added

This commit is contained in:
2026-06-03 16:28:49 +03:30
parent c52a234835
commit c930c26589
4 changed files with 121 additions and 0 deletions
@@ -0,0 +1,70 @@
<?php
namespace App\Http\Controllers;
use App\Models\ChatTopic;
use Illuminate\Http\Request;
class ChatTopicController extends Controller
{
// Suggested chat topics (موضوعات پیشنهادی). Active only unless include_inactive=1.
public function index(Request $request)
{
$query = ChatTopic::query();
if (!$request->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']);
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ChatTopic extends Model
{
protected $fillable = ['title', 'description', 'order', 'is_active'];
protected $casts = [
'is_active' => 'boolean',
'order' => 'integer',
];
}
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chat_topics', function (Blueprint $table) {
$table->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');
}
};
+5
View File
@@ -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 () {