<commit_before><?php

namespace Modules\Core\Repositories\Eloquent;

use Illuminate\Support\Str;
use Modules\Core\Repositories\SlugRepository;

abstract class EloquentSlugRepository extends EloquentBaseRepository implements SlugRepository
{
    /**
     * Find a resource by an given Slug.
     *
     * @param string $slug
     *
     * @return object
     */
    public function findBySlug($slug)
    {
        return $this->findWhere(['slug' => $slug])->first();
    }

    /**
     * Generate a unique Slug for a given Title.
     *
     * @param string $title
     *
     * @return object
     */
    public function getSlugForTitle($title)
    {
        $slug = Str::slug($title);
        $latestSlug = $this->model->whereRaw("slug RLIKE '^{$slug}(-[0-9]*)?$'")->latest()->value('slug');

        if ($latestSlug) {
            $pieces = explode('-', $latestSlug);
            $number = end($pieces);

            return $slug.'-'.($number + 1);
        }

        return $slug;
    }
}
<commit_msg>updateBySlug function<commit_after><?php

namespace Modules\Core\Repositories\Eloquent;

use Illuminate\Support\Str;
use Modules\Core\Repositories\SlugRepository;
use Prettus\Validator\Contracts\ValidatorInterface;
use Prettus\Repository\Contracts\RepositoryInterface;

abstract class EloquentSlugRepository extends EloquentBaseRepository implements SlugRepository
{
    /**
     * Find a resource by an given Slug.
     *
     * @param string $slug
     *
     * @return object
     */
    public function findBySlug($slug)
    {
        return $this->findWhere(['slug' => $slug])->first();
    }

    /**
     * Update a entity in repository by id
     *
     * @throws ValidatorException
     * @param array $attributes
     * @param $id
     * @return mixed
     */
    public function updateBySlug(array $attributes, $slug)
    {
        $album = $this->findBySlug($slug);
        return $this->update($attributes, $album->id);
    }

    /**
     * Generate a unique Slug for a given Title.
     *
     * @param string $title
     *
     * @return object
     */
    public function getSlugForTitle($title)
    {
        $slug = Str::slug($title);
        $latestSlug = $this->model->whereRaw("slug RLIKE '^{$slug}(-[0-9]*)?$'")->latest()->value('slug');

        if ($latestSlug) {
            $pieces = explode('-', $latestSlug);
            $number = end($pieces);

            return $slug.'-'.($number + 1);
        }

        return $slug;
    }
}

{'fraction_non_alphanumeric': 0.14442190669371197, 'fraction_numerical': 0.002434077079107505, 'mean_word_length': 2.3873626373626373, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, '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': '7384054', 'n_tokens_mistral': 776, 'n_tokens_neox': 784, 'n_words': 163}