<commit_before><?php namespace Eloquent\Dialect;

trait Json
{
    /**
     * List of known PSQL JSON operators
     *
     * @var array
     */
    public static $jsonOperators = [
        '->',
        '->>',
        '#>',
        '#>>' ];

    /**
     * @var array
     */
    private $jsonAttributes = [];

    /**
     * Boot the Json trait for a model.
     *
     * @return void
     */
    public static function bootJson()
    {
        self::loading(function($obj)
        {
            $obj->inspectJsonColumns();
        });
    }

    /**
     * Decodes each of the declared JSON attributes and records the attributes
     * on each
     *
     * @return void
     */
    public function inspectJsonColumns()
    {
        foreach ($this->jsonColumns as $col) {
            $this->hidden[] = $col;
            $obj = json_decode($this->$col);

            if (is_object($obj)) {
                foreach ($obj as $key => $value) {
                    $this->flagJsonAttribute($key, $col);
                    $this->appends[] = $key;
                }<commit_msg>Override newFromBuilder<commit_after><?php namespace Eloquent\Dialect;

trait Json
{
    /**
     * List of known PSQL JSON operators
     *
     * @var array
     */
    public static $jsonOperators = [
        '->',
        '->>',
        '#>',
        '#>>' ];

    /**
     * @var array
     */
    private $jsonAttributes = [];

	/**
	 * Create a new model instance that is existing.
	 * Overrides parent to set Json columns.
	 *
	 * @param  array  $attributes
	 * @param  string|null  $connection
	 * @return static
	 */
	public function newFromBuilder($attributes = array(), $connection = null)
	{
		$model = parent::newFromBuilder($attributes, $connection);
		$model->inspectJsonColumns();
		return $model;
	}

    /**
     * Decodes each of the declared JSON attributes and records the attributes
     * on each
     *
     * @return void
     */
    public function inspectJsonColumns()
    {
        foreach ($this->jsonColumns as $col) {
            $this->hidden[] = $col;
            $obj = json_decode($this->$col);

            if (is_object($obj)) {
                foreach ($obj as $key => $value) {
                    $this->flagJsonAttribute($key, $col);
                    $this->appends[] = $key;
                }
{'fraction_non_alphanumeric': 0.14088159031979255, 'fraction_numerical': 0.0, 'mean_word_length': 1.691860465116279, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '4893131', 'n_tokens_mistral': 678, 'n_tokens_neox': 661, 'n_words': 164}