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 #26

Closed psychonetic closed 6 years ago

psychonetic commented 6 years ago

Hello,

if I try to create an entity, I get the following error: Class name must be a valid object or a string

The error occurs inside Illuminate/Database/Eloquent/Concerns/HasRelationships at:

protected function newRelatedInstance($class)
    {
        //dd($class) gives null.
    return tap(new $class, function ($instance) {
            if (! $instance->getConnectionName()) {
                $instance->setConnection($this->connection);
            }
        });
    }

My code:

//attribute creation

app('rinvex.attributes.attribute')->create([
            'slug' => 'size',
            'name' => 'Product Size',
            'type' => 'Rinvex\Attributes\Models\Type\Varchar',
            'entities' => ['App\Models\Article'],
        ]);

//Article (yes, it uses the attributableTrait)

$article = Article::find(1);
        $article->size = "m";
        $article->save();

Any idea? Laravel version is 5.5 and used attributes version is dev-develop 8bce023.

Omranic commented 6 years ago

Can you confirm please what’s in your attribute_entity table? That would help troubleshoot this issue..

psychonetic commented 6 years ago

Here you go:

see bildschirmfoto 2018-01-04 um 22 01 31

(saving in version 0.0.3 works as expected, but in the 0.0.3 branch I am unable to get the data as mentioned in #27 )

tongkai-wzq commented 6 years ago

the same problem to me !

weusder commented 6 years ago

I'm also having the same problem

tongkai-wzq commented 6 years ago

please turn type to alias !

app('rinvex.attributes.attribute')->create([ 'slug' => 'size', 'name' => 'Product Size', 'type' => 'varchar', 'entities' => ['App\Models\Article'], ]);

Array ( [boolean] => Rinvex\Attributes\Models\Type\Boolean [datetime] => Rinvex\Attributes\Models\Type\Datetime [integer] => Rinvex\Attributes\Models\Type\Integer [text] => Rinvex\Attributes\Models\Type\Text [varchar] => Rinvex\Attributes\Models\Type\Varchar )

weusder commented 6 years ago

kfja85 thanks for the help, it worked!

psychonetic commented 6 years ago

@kfja85 Works perfectly! Unfortunately I am still not able to get the data. Eg. Article::with('size')->get() Size is still null.

Did you manage this? @kfja85 @weusder

@Omranic Can you please update the documentation and include the changes?

Omranic commented 6 years ago

@kfja85 @weusder Sorry for the delay, and yes that make sense now. Docs fixed to reflect the new type aliases at 102b93035355426d08f49c7176d6eb1cde9b48fb

@psychonetic I've done few tests again now & everything seems to be working fine. What you need to make sure of is the following:

If all these three tables has the correct info, then you should retrieve the value. If not, then please screenshot or dump the three tables here and I'll try to go through it & see what's wrong..

psychonetic commented 6 years ago

@Omranic That sounds good!

Yeah, I show you.

Attributes table:

bildschirmfoto 2018-01-09 um 16 53 24

Attributes entity table:

bildschirmfoto 2018-01-09 um 16 53 44

Attributes Varchar Table:

bildschirmfoto 2018-01-09 um 16 53 53

So everything should be fine in my opinion.

Omranic commented 6 years ago

Seems to be fine, and I've reproduced the same data as yours & it worked like a charm. One last thing, if you've cache enabled please disable caching & check again and let me know if that makes any difference. It's good to flush app cache for the sake of troubleshooting..

psychonetic commented 6 years ago

@Omranic I tried to clean the cache, but no change. Any further idea? Maybe I will try to create a project later, only with your package and just laravel. Otherwise I don't know.

@kfja85 @weusder Do you the same problem or is it working as expected?

Omranic commented 6 years ago

I assume that your App\Models\Article model already using Rinvex\Attributes\Traits\Attributable trait, and you're retrieving it normally like:

$article = \App\Models\Article::with(['size'])->find(1);
dd($article->size);

If that's what you're doing and you still get nothing, then I'm not sure it's something related to this package. It's working with or without any other packages without a problem, I replicated the same setup & even same table data and can't reproduce your issue. Make sure there's no other size attribute used by the same model or attached by any other package in someway, otherwise please try to reproduce in a new project and mention the steps on how can we reproduce the issue in order to troubleshoot it.

For now I'll close this issue as it's not confirmed as an issue, but feel free to open it again or open a new one for further assistance.