rcerljenko/laravel-openai-moderation

Laravel package for OpenAI Moderation API

Installs: 1 249

Dependents: 0

Suggesters: 0

Security: 0

Stars: 25

Watchers: 3

Forks: 2

Open Issues: 0

pkg:composer/rcerljenko/laravel-openai-moderation

1.1.0 2023-02-27 15:19 UTC

This package is auto-updated.

Last update: 2025-09-27 21:15:47 UTC


README

Laravel validation Rule using OpenAI Moderation API. Gives you a way to validate your form requests for inappropriate content.

Installation

Standard Composer package installation:

composer require rcerljenko/laravel-openai-moderation

Usage

  1. Publish config and translation files.
php artisan vendor:publish --provider="RCerljenko\LaravelOpenAIModeration\ServiceProvider"
  1. Set your OpenAI API key and enable package via newly created config file => config/openai.php

  2. Use provided rule with your validation rules.

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use RCerljenko\LaravelOpenAIModeration\Rules\OpenAIModeration;

class StoreText extends FormRequest
{
 /**
  * Determine if the user is authorized to make this request.
  */
 public function authorize(): bool
 {
  return true;
 }

 /**
  * Get the validation rules that apply to the request.
  */
 public function rules(): array
 {
  return [
   'text' => ['required', 'string', new OpenAIModeration],
  ];
 }
}