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

Base table or view not found #158

Closed kis60 closed 3 years ago

kis60 commented 3 years ago

My model class:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Rinvex\Attributes\Traits\Attributable;

class Poll extends Model
{
    use Attributable;
    protected $fillable = ['link'];
}

I have registered type and entity

class AppServiceProvider extends ServiceProvider
{
    ...
    public function boot()
    { 
        Attribute::typeMap([
            'varchar' => \Rinvex\Attributes\Models\Type\Varchar::class
        ]);
        app('rinvex.attributes.entities')->push(\App\Models\Poll::class);
    }
}

I have successfully created attribute: app('rinvex.attributes.attribute')->create(['slug' => 'link', 'type' => 'varchar', 'name' => 'Link', 'entities' => ['App\Models\Poll']]);

But when adding an entity

$pool = Poll::create(['link' => 'AAA']);
$pool->save();

I get the error

Base table or view not found: 1146 Table 'eav.polls' doesn't exist (SQL: insert into 'polls' ('updated_at', 'created_at') values (2021-06-10 19:16:50, 2021-06-10 19:16:50))

What's wrong? Thanks in advance.

Omranic commented 3 years ago

Did you create & execute a migration for your Poll model? If no, please do so. This is related to your Poll model, not this package. For more info check:

https://laravel.com/docs/8.x/migrations

https://laravel.com/docs/8.x/eloquent

kis60 commented 3 years ago

Did you create & execute a migration for your Polls model?

Yes, I did. But, while doing $p = Poll::where('link', 'AAA')->first(); ("Rinvex Attributes tries to do everything in the same way Eloquent would normally do" !) I got QueryException "Column not found: 1054 Unknown column 'link' in 'where clause'". What's wrong?

Omranic commented 3 years ago

Can you execute the following code and tell me what's the output: app('rinvex.attributes.attribute')->where('slug', 'link')->get();

Also can you confirm what's your fully qualified Poll model namespace.

kis60 commented 3 years ago

Hello. Thanks for answer.

Tuesday, June 15, 2021, 11:11:22 AM, you wrote:

Can you execute the following code and tell me what's the output: app('rinvex.attributes.attribute')->where('slug', 'link')->get(); I got object of type \Illuminate\Database\Eloquent\Collection. Field items is array with 1 element.

Also can you confirm what's your fully qualified Poll model namespace. namespace App\Models;

use Illuminate\Database\Eloquent\Model; use Rinvex\Attributes\Traits\Attributable;

class Poll extends Model { use Attributable;

protected $table ='polls';

protected $fillable = ['link'];

}

Query SELECT * FROM attributes; returns 1 link {"en": "Link"} (null) 1 (null) varchar 0 0 (null) 10.06.2021 17:57:07 10.06.2021 17:57:07

-- Best regards, Yuri D.Kislitsky @.***

-- Это сообщение проверено на вирусы антивирусом Avast. https://www.avast.com/antivirus

vahidalvandi commented 2 years ago

I was a little confused Why should the Product table be created and according to the document, when I want to create a custom attribute price, it gives an error that the price column is not available !!!

Omranic commented 2 years ago

@vahidalvandi What product table? 🙂

vahidalvandi commented 2 years ago

hi @Omranic product table in https://github.com/rinvex/laravel-attributes#assigning-values and according @kis60 poll table . please show a demo

Omranic commented 2 years ago

This is just an example, you need to create that table yourself. That example could be Product or Article or anything else, that's your business logic and not within the scope of this package to cover.

vahidalvandi commented 2 years ago

i need this senario do it work ?

i have lead table with three columns (id , name , lname) . i want admin can add multi cloumn like mobile , email without change table .

Omranic commented 2 years ago

Yes it works, but you can achieve that through different ways. You can use this EAV package, or use a more simple approach the get the job done as well https://github.com/spatie/laravel-schemaless-attributes

That's why I mentioned previously if you don't know EAV and want that model specifically, you probably don't need it at all, and probably there's a better more simple solution to solve your challenge.