<commit_before><?php

namespace Luminary\Models\Repositories;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Luminary\Contracts\Entity\Repository as RepositoryContract;
use Luminary\Database\Eloquent\Relations\ManageRelations;
use Luminary\Services\ApiRequest\RequestRepositoryTrait;

class Repository implements RepositoryContract
{
    use ManageRelations;
    use RequestRepositoryTrait;

    /**
     * Retrieve all records
     *
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public static function all() :Collection
    {
        return static::builder([], true)->getModel()->all();
    }

    /**
     * Find a record by id
     *
     * @param $id
     * @param array $without
     * @return \Illuminate\Database\Eloquent\Model
     */
    public static function find($id, $without = ['archived']) :Model
    {
        return static::findAll((array) $id, $without)->first();
    }

    /**
     * Find multiple records by id
     *
     * @param array $ids
     * @param array $without
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public static function findAll(array $ids, $without = []) :Collection
    {
        return static::builder($without, true)->find((array) $ids);
    }

    /**
     * Create a new record
     *
     * @param array $data
     * @param array $relationships ['relNameOne' => 9, 'relNameMany' => [1,2,3,4]]
     * @return Model
     */
    public static function create(array $data, array $relationships = []) :Model
    {
        $model = static::builder()->create($data);

        if(count($relationships)) {
            static::createRelationships($model, $relationships);
        }

        return $model;
    }

    /**
     * Create multiple new records with
     * an array of attribute arrays
     *
     * @param array $data
     * @return string|false
     */
    public static function createAll(array $data)
    {
        $now = Carbon::now()->toDateTimeString();

        $timestamps = [
            'created_at'=> $now,
            'updated_at'=> $now
        ];

        $data = collect($data)->transform(
            function ($attributes) use ($timestamps) {
                return array_merge($attributes, $timestamps);
            }
        )->all();

        $insert = static::builder()::insert($data);

        return $insert ? (string) $now : false;
    }

    /**
     * Update a record by id
     *
     * @param $id
     * @param array $data
     * @param array $relationships ['relNameOne' => 9, 'relNameMany' => [1,2,3,4]]
     * @return \Illuminate\Database\Eloquent\Model
     */
    public static function update($id, array $data, array $relationships = []) :Model
    {
        $model = static::find($id, $without = ['archived', 'trashed']);

        $model->update($data);

        if(count($relationships)) {
            $relationships = static::fillMissingRelationships($model, $relationships);
            static::updateRelationships($model, $relationships);
        }

        return $model;
    }

    /**
     * Update a record by id
     *
     * @param array $ids
     * @param array $data
     * @return bool
     */
    public static function updateAll(array $ids, array $data) :bool
    {
        return static::builder(['archived', 'trashed'], true)->whereIn('id', $ids)->update($data);
    }

    /**
     * Delete a record by id
     *
     * @param $id
     * @return bool
     */
    public static function delete($id) :bool
    {
        return static::builder(['archived'], true)->destroy($id);
    }

    /**
     * Delete multiple records
     * by ID
     *
     * @param array $ids
     * @return bool
     */
    public static function deleteAll(array $ids) :bool
    {
        return static::builder(['archived'], true)->destroy((array) $ids);
    }
}<commit_msg>Updated repository to trigger deleted eloquent event<commit_after><?php

namespace Luminary\Models\Repositories;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Luminary\Contracts\Entity\Repository as RepositoryContract;
use Luminary\Database\Eloquent\Relations\ManageRelations;
use Luminary\Services\ApiRequest\RequestRepositoryTrait;

class Repository implements RepositoryContract
{
    use ManageRelations;
    use RequestRepositoryTrait;

    /**
     * Retrieve all records
     *
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public static function all() :Collection
    {
        return static::builder([], true)->getModel()->all();
    }

    /**
     * Find a record by id
     *
     * @param $id
     * @param array $without
     * @return \Illuminate\Database\Eloquent\Model
     */
    public static function find($id, $without = ['archived']) :Model
    {
        return static::findAll((array) $id, $without)->first();
    }

    /**
     * Find multiple records by id
     *
     * @param array $ids
     * @param array $without
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public static function findAll(array $ids, $without = []) :Collection
    {
        return static::builder($without, true)->find((array) $ids);
    }

    /**
     * Create a new record
     *
     * @param array $data
     * @param array $relationships ['relNameOne' => 9, 'relNameMany' => [1,2,3,4]]
     * @return Model
     */
    public static function create(array $data, array $relationships = []) :Model
    {
        $model = static::builder()->create($data);

        if(count($relationships)) {
            static::createRelationships($model, $relationships);
        }

        return $model;
    }

    /**
     * Create multiple new records with
     * an array of attribute arrays
     *
     * @param array $data
     * @return string|false
     */
    public static function createAll(array $data)
    {
        $now = Carbon::now()->toDateTimeString();

        $timestamps = [
            'created_at'=> $now,
            'updated_at'=> $now
        ];

        $data = collect($data)->transform(
            function ($attributes) use ($timestamps) {
                return array_merge($attributes, $timestamps);
            }
        )->all();

        $insert = static::builder()::insert($data);

        return $insert ? (string) $now : false;
    }

    /**
     * Update a record by id
     *
     * @param $id
     * @param array $data
     * @param array $relationships ['relNameOne' => 9, 'relNameMany' => [1,2,3,4]]
     * @return \Illuminate\Database\Eloquent\Model
     */
    public static function update($id, array $data, array $relationships = []) :Model
    {
        $model = static::find($id, $without = ['archived', 'trashed']);

        $model->update($data);

        if(count($relationships)) {
            $relationships = static::fillMissingRelationships($model, $relationships);
            static::updateRelationships($model, $relationships);
        }

        return $model;
    }

    /**
     * Update a record by id
     *
     * @param array $ids
     * @param array $data
     * @return bool
     */
    public static function updateAll(array $ids, array $data) :bool
    {
        return static::builder(['archived', 'trashed'], true)->whereIn('id', $ids)->update($data);
    }

    /**
     * Delete a record by id
     *
     * @param $id
     * @return bool
     */
    public static function delete($id) :bool
    {
        static::builder(['archived'], true)->get()->each(function($model) {
            $model->delete();
        });

        return true;
    }

    /**
     * Delete multiple records
     * by ID
     *
     * @param array $ids
     * @return bool
     */
    public static function deleteAll(array $ids) :bool
    {
        return static::builder(['archived'], true)->delete((array) $ids);
    }
}
{'fraction_non_alphanumeric': 0.14083248212461696, 'fraction_numerical': 0.002553626149131767, 'mean_word_length': 2.3474358974358975, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '2755870', 'n_tokens_mistral': 2326, 'n_tokens_neox': 2259, 'n_words': 538}