rinvex / laravel-attributes

⚠️ [ABANDONED] Rinvex Attributable is a robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
MIT License
433 stars 104 forks source link

Method Illuminate\Support\Collection::add does not exist. #38

Closed mepoohsta closed 6 years ago

mepoohsta commented 6 years ago

I don't know exactly what I need to do.

I want to add multiple values to attr. Trying this.

$model->tags->add(['Alexandria', 'Cairo'])

I added this code to my Model

`` /**

Get this image

IsraelOrtuno commented 6 years ago

Could you add a screenshot of your database state? The values related to this attribute.

mepoohsta commented 6 years ago

I solved this issue by overriding some methods. Maybe, this? i forget.

public function pluck($value, $key = null)
    {
        $attribute = app('rinvex.attributes.attribute')->find($this->attribute->id);
        //$items = $attribute->values(Attribute::getTypeModel($this->attribute->getAttribute('type')))->get();

        $model = $this->entity;
        $attribute = $this->attribute;
        $attr_type = Attribute::getTypeModel($attribute->getAttribute('type'));

        $instance = new $attr_type();

        $items =$instance
                ->Leftjoin($model->getTable(), $model->getTable().'.id', '=', $instance->getTable().'.entity_id')
                ->where([
                    ['entity_id', '=', $model->id],
                    ['attribute_id', '=', $attribute->id],
                ])->get();

        $items->entity = $model;
        $items->attribute = $this->attribute;
        $key = null;

        $class = new static();
        $class->attribute = $this->attribute;
        $class->entity = $this->entity;
        $class->items = Arr::pluck($items->items, $value, $key);

        return $class;
    }
IsraelOrtuno commented 6 years ago

Not sure right now. I would need to have the same state in the database to try to reproduce the issue.

mepoohsta commented 6 years ago

It was not in the database, some method was returned not the ValueCollection() but the Collection().

Omranic commented 6 years ago

@mepoohsta thank you for reaching out, and sorry for the delay! Well, buddy there's no add method in Laravel's Collections! AndValueCollection actually inherits from it, so you just need to use push like normal, make sure to READ THE WHOLE DOCUMENTATION as it's really mandatory to understand how this package works. And you can visit official Laravel Collections page too 🙂

P.S. If you're using this package for managing tags, it's not efficient and highly not recommended. You can use Rinvex Tags instead.