PHP code example of edulazaro / laratox

1. Go to this page and download the library: Download edulazaro/laratox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

edulazaro / laratox example snippets


use ToxicFilter;

$verdict = ToxicFilter::text($comment->body)->check();

if ($verdict->blocked()) {
    return back()->withErrors(['body' => $verdict->reason()]);
}

$comment->hidden = $verdict->needsReview();

ToxicFilter::text($listing->description)
    ->policy('marketplace')     // one of your policies, instead of the default
    ->project('shop')           // one of your projects, instead of TOXICFILTER_PROJECT
    ->locale('es')              // the language it should be in
    ->surface('listing')        // where it appears
    ->reference("listing_{$listing->id}")
    ->check();

ToxicFilter::text($body)->check();
ToxicFilter::name($user->username)->check();
ToxicFilter::email($request->email)->check();
ToxicFilter::url($request->website)->check();
ToxicFilter::image($photo->url)->check();
ToxicFilter::imageData($upload->get())->check();
ToxicFilter::prompt($question)->check();
ToxicFilter::conversation($messages)->check();
ToxicFilter::signup(['name' => $name, 'email' => $email, 'bio' => $bio])->check();

use ToxicFilter\Exception\ApiError;
use ToxicFilter\Exception\QuotaExhausted;

try {
    $verdict = ToxicFilter::text($comment->body)->check();
} catch (QuotaExhausted $e) {
    // Out of credits: $e->remaining(), $e->

use EduLazaro\Laratox\Rules\Moderated;

$request->validate([
    'body' => ['bail', '

$rule = Moderated::text();

$request->validate(['body' => ['se;

$fake = ToxicFilter::fake();                                  // everything allowed

$fake->shouldBlock('spam', 'Contains a referral link');       // block everything
$fake->shouldReview('toxicity', when: fn ($request) =>        // or only some requests
    str_contains($request['body']['content'] ?? '', 'idiot'));

$fake->assertSent(fn ($request) => $request['path'] === '/api/v1/text');
$fake->assertSentCount(1);
bash
php artisan laratox:ping
bash
php artisan vendor:publish --tag=laratox-config