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

Getting Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column' on new installation #84

Closed iamsayantan closed 5 years ago

iamsayantan commented 5 years ago

After following the installation instruction I can not update custom attributes in the table. I am using laravel-attributes: ^1.0. I have registered the types and entities in boot method of AppServiceProvider.php AppServiceProvider.php

Attribute::typeMap([
     varchar' => \Rinvex\Attributes\Models\Type\Varchar::class, 
     'text'    => \Rinvex\Attributes\Models\Type\Text::class,
     'boolean' => \Rinvex\Attributes\Models\Type\Boolean::class,
     'integer' => \Rinvex\Attributes\Models\Type\Integer::class,
     'datetime' => \Rinvex\Attributes\Models\Type\Datetime::class
 ]);

 app('rinvex.attributes.entities')->push(\App\CompanyBranch::class);

And created an attribute for CompanyBranch like this, which worked fine.

app('rinvex.attributes.attribute')->create([
    'slug'        => 'pan_card',
    'type'        => 'varchar',
    'name'        => 'Pan Card Details',
    'is_required' => false,
    'description' => 'PAN Card details of the branch',
    'entities'    => ['\App\CompanyBranch'],
]);

This created a data in attributes table and attribute_entity table. But when I try to save value to the attribute

$branch = \App\CompanyBranch::find(2);
$branch->pan_card = 'CFAPF7177N';
$branch->save();

laravel is throwing this exception

Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pan_card' in 'field list' (SQL: update company_branches set updated_at = 2019-04-12 06:17:38, pan_card = CFAPF7177N where id = 2)'

Also the special relation eav is not working. $branch->load('eav'); throws RelationNotFoundException exception. Anything I am doing wrong? Any help would be appricated.

iamsayantan commented 5 years ago

This is my bad. Apparently the full path for model should be App\CompanyBranch instead of \App\CompanyBranch. It's working now.

Omranic commented 4 years ago

Good to know you figured it out :)