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
434 stars 104 forks source link

Class name must be a valid object or a string #63

Closed rez1dent3 closed 6 years ago

rez1dent3 commented 6 years ago

Hello. I can't deal with the package, and I need help.

My migration. database/migrations/2017_10_31_072845_create_images_table.php

...
    /**
     * @return array
     */
    protected function attributes(): array
    {
        return [
            [
                'type' => 'varchar',
                'name' => 'MIME type',
                'slug' => 'mime',
                'entities' => [\App\Models\Image::class],
                'group' => 'metadata',
            ],
            [
                'type' => 'integer',
                'name' => 'Image width',
                'slug' => 'width',
                'entities' => [\App\Models\Image::class],
                'group' => 'metadata',
            ],
            [
                'type' => 'integer',
                'name' => 'Image height',
                'slug' => 'height',
                'entities' => [\App\Models\Image::class],
                'group' => 'metadata',
            ],
            [
                'type' => 'integer',
                'name' => 'Image size',
                'slug' => 'size',
                'entities' => [\App\Models\Image::class],
                'group' => 'metadata',
            ]
        ];
    }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('images', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->integer('bucket_id');
            $table->integer('user_id');
            $table->boolean('processed')->default(0);
            $table->timestamps();
            $table->unique(['name']);
        });

        foreach ($this->attributes() as $attribute) {
            app('rinvex.attributes.attribute')
                ->create($attribute);
        }
    }
...

Providers/AppServiceProvider.php

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        \app('rinvex.attributes.entities')->push(Image::class);
    }

App\Models\Image.php

namespace App\Models;

use Rinvex\Attributes\Traits\Attributable;

class Image extends Model
{
    use Attributable;
    protected $with = ['eav'];
   ...
}

Console/Commands/TestCommand.php

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $image = Image::query()->first();

        if (!$image) {
            $image = new Image();
            $image->name = Image::generateName(1, 'png');
            $image->bucket_id = 1;
            $image->user_id = 1;
            $image->save();
        }
    }

_2018-06-29_07-54-41

rez1dent3 commented 6 years ago

image

rez1dent3 commented 6 years ago

image

rez1dent3 commented 6 years ago

other tables are empty

rez1dent3 commented 6 years ago

"rinvex/attributes": "^0.0" // installed version 0.0.6

IsraelOrtuno commented 6 years ago

Did you register the Integer, Varchar .. values?

IsraelOrtuno commented 6 years ago

https://github.com/rinvex/attributes#register-your-types

rez1dent3 commented 6 years ago

Thank you!

uphlewis commented 5 years ago

I found myself here searching for the same exception after I changed a type's name without clearing file cache (existing attributes were cached with the old type name). Maybe it would be helpful to identify this problem in the package and throw an exception with a clear message, rather than letting the bug trickle down and get thrown as a confusing exception in Eloquent.