kodeine / laravel-meta

Fluent Meta Data for Eloquent Models, as if it is a property on your model
MIT License
400 stars 90 forks source link

Set model attribute for preventing metas to being populated on toArray() #75

Closed dhcmega closed 4 years ago

dhcmega commented 4 years ago

Hi @kodeine This PR adds a conditionl to the method that returns the model as an array for setting if the generated array should or should not include all the metas.

This is my very first PR. Hope I have done it properly

Thanks!

dhcmega commented 4 years ago

I think I could also add this method to be used instead of toArray() for static calls like:

$users = User::find(1)->toArrayWithoutMetas();

    /**
     * Convert the model instance to an array.
     *
     * @return array
     */
    public static function toArrayWithoutMetas()
    {
        return parent::toArray();
    }
dhcmega commented 4 years ago

This is another alternative:

$users = User::find(1)->withoutMetas();

    /**
     * Convert the model instance to an array.
     *
     */
    public function withoutMetas()
    {
        $this->hideMeta = true;

        return $this;
    }