<commit_before><?php

namespace App\Listeners;

use App\Events\SluggableCreating;

class SlugModel
{
    public function __construct()
    {
        //
    }

    public function handle(SluggableCreating $event)
    {
        if (empty($event->sluggable->id)) {
            $id = $template = $event->sluggable->getSlugID();
            $class = get_class($event->sluggable);
            $index = 1;

            do {
                $test = $class::where('id', $id)->withTrashed()->first();
                if ($test == null)
                    break;

                $id = $template . '-' . $index++;
            } while(true);

            $event->sluggable->id = $id;
        }
    }
}<commit_msg>fix controllo ID duplicati<commit_after><?php

namespace App\Listeners;

use App\Events\SluggableCreating;

class SlugModel
{
    public function __construct()
    {
        //
    }

    public function handle(SluggableCreating $event)
    {
        if (empty($event->sluggable->id)) {
            $id = $template = $event->sluggable->getSlugID();
            $class = get_class($event->sluggable);
            $index = 1;

            do {
                if (in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($class)))
                    $test = $class::where('id', $id)->withTrashed()->first();
                else
                    $test = $class::where('id', $id)->first();

                if ($test == null)
                    break;

                $id = $template . '-' . $index++;
            } while(true);

            $event->sluggable->id = $id;
        }
    }
}
{'fraction_non_alphanumeric': 0.153125, 'fraction_numerical': 0.00125, 'mean_word_length': 1.6117455138662315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5809225', 'n_tokens_mistral': 492, 'n_tokens_neox': 467, 'n_words': 84}