Код: Выделить всё
Route::post('/groups', [GroupController::class, 'store']);
Вот соответствующий код:
Групповые маршруты:
Код: Выделить всё
Route::middleware('auth:api')->group(function () {
// Group Routes
Route::get('/groups', [GroupController::class, 'index']);
Route::post('/groups', [GroupController::class, 'store']); // Create Group endpoint
Route::get('/groups/{group}', [GroupController::class, 'show']);
Route::put('/groups/{group}/edit', [GroupController::class, 'update']);
});
Код: Выделить всё
Schema::create('groups', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('description')->nullable();
$table->string('group_category')->nullable();
$table->enum('visibility', ['public', 'private'])->default('public');
$table->decimal('price', 8, 2)->default(0); // Default price is 0 (free)
$table->boolean('is_badge_required')->default(false);
$table->foreignId('badge_needed')->nullable()->constrained('badges')->nullOnDelete(); // Links to badges table
$table->timestamps();
});
Код: Выделить всё
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'group_category' => 'nullable|string|max:255',
'visibility' => 'required|in:public,private',
'price' => 'nullable|numeric|min:0',
'is_badge_required' => 'required|boolean',
'badge_needed' => 'nullable|exists:badges,id',
];
}
Код: Выделить всё
storeКод: Выделить всё
public function store(StoreGroupRequest $request): JsonResponse
{
if (!Auth::user()->can('create-group')) {
return new JsonResponse([
'message' => 'You are not allowed to create groups.'
], Response::HTTP_FORBIDDEN);
}
$group = Group::create($request->validated());
return new JsonResponse([
'message' => 'Group created successfully.'
], Response::HTTP_CREATED);
}

Подробнее здесь: https://stackoverflow.com/questions/792 ... -not-found
Мобильная версия