GithubHelp home page GithubHelp logo

rinvex / laravel-attributes Goto Github PK

View Code? Open in Web Editor NEW
432.0 432.0 101.0 461 KB

⚠️ [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.

License: MIT License

PHP 100.00%
attributes custom dynamic eloquent fields laravel php

laravel-attributes's People

Contributors

balping avatar dependabot-preview[bot] avatar israelortuno avatar javoscript avatar michal-kusy avatar omranic avatar psychonetic avatar rattone avatar wuwx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-attributes's Issues

Problems with traits HasTranslations and ValidatingTrait

The "Rinvex\Attributes\Models\Attribute" class has two traits:
Rinvex\Support\Traits\HasTranslations;
Rinvex\Support\Traits\ValidatingTrait

And these traits don't exists in the package... So I have an error when try to use it.

Field 'entity_id' doesn't have a default value

Hi Pro,
I using code below for create new attribute.

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

but system show error:

SQLSTATE[HY000]: General error: 1364 Field 'entity_id' doesn't have a default value (SQL: insert into attribute_entity (entity_type, attribute_id, updated_at, created_at) values

Can help me how to fix it?
Thanks

I can't run php artisan rinvex:migrate:attributes

Hi guys !
I can't run php artisan rinvex:migrate:attributes. it do not work
run: php artisan rinvex:migrate:attributes
i got an errror:
There are no commands defined in the "rinvex:migrate" namespace.
Anybody can help me?

Too few arguments to function Rinvex/Attributes/Models/Attribute::values()

Hi! Great package, thanks.

Stumbled onto the above error when trying to lazy load $attribute->values

Would there be any drawbacks of changing the method signature of Rinvex/Attributes/Models/Attribute::values() slightly?

Currently the method looks like this:

    /**
     * Get the entities attached to this attribute.
     *
     * @param string $value
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function values(string $value): HasMany
    {
        return $this->hasMany($value, 'attribute_id', 'id');
    }

So trying to access $attribute->values as a dynamic property throws an error because Attribute::values() expects a $value argument.

My proposed fix:

    /**
     * Get the entities attached to this attribute.
     *
     * @param string|null [$valueModel]
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function values(string $valueModel = null): HasMany
    {
        if (!$valueModel && array_has($this->attributes, 'type')) {
            $valueModel = self::getTypeModel($this->attributes['type']);
        }

        return $this->hasMany($valueModel, 'attribute_id', 'id');
    }

Thoughts ?

Trait 'Rinvex\Support\Traits\HasTranslations' not found

D:\phpStudy\site\weyoung\vendor\rinvex\attributes\src\Models\Attribute.php

 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute ordered($direction = 'asc')
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereDefault($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereGroup($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereIsCollection($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereIsRequired($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereSlug($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereSortOrder($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Attributes\Models\Attribute whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Attribute extends Model implements AttributeContract, Sortable
{
    use HasSlug;
    use SortableTrait;
    use HasTranslations;
    use ValidatingTrait;
    use CacheableEloquent;
 
    /**
     * {@inheritdoc}
     */
    protected $fillable = [
        'name',
        'slug',
        'description',
        'sort_order',
        'group',
        'type',
        'entities',
        'is_required',
        'is_collection',
        'default',
    ];
 
    /**

Arguments

"Trait 'Rinvex\Support\Traits\HasTranslations' not found"

Slug should be snake_case even it's manually provided

As of now, the slug is automatically generated in an snake_case style only when it gets generated using the Sluggable package (no slug provided when creating the attribute).

When we create an attribute providing a slug, it won't get formatted as snake_case.

Reproduce

app('rinvex.attributes.attribute')->create([
    'slug' => 'foo-bar',
    'type'     => 'integer',
    'name'     => 'Count',
    'entities' => ['App\User'],
])

This will produce a foo-bar slug rather than foo_bar.

EAV values empty

If I create an entity and let's say we have a size attribute, the size is always null.

$art = Article::find(1);  //$art->size = null

$art = Article::with('eav)->get(); //size also empty

//in Model Article  protected $with = ['eav'];

$art = Article::all(); //size also empty

Is there anything wrong how I access the size or is this a bug?
The value in the database is correct. So in the database I can find the size value (it's "m").

Laravel 5.5, attributes Version is 0.0.3.

(1/1) MassAssignmentException content

On running
$value = new Varchar(['content' => 'Alexandria', 'attribute_id' => 1, 'entity_type' => 'App\Company', 'entity_id' => 1]);

Mass Assignment error shows up
How to assign attribute to entity and push value?

PostgreSQL error

I'm trying to use your library with pgsql. No luck so far!

   Illuminate\Database\QueryException  : SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: text ->> unknown
LINE 1: ...tes" where 0 = 1 order by "sort_order" asc, "name"->>'$en' a...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts. (SQL: select * from "attributes" where 0 = 1 order by "sort_order" asc, "name"->>'$en' asc)

Not working with laravel 5.5

HI Omranic,

I found the laravel-attributes package and feel this has great potential. Thank you very much for your effort building it ! I found out that the current version doesn't support Laravel 5.5. You mentioned because it is still in development release and you want to support latest laravel version. However 5.5 is the LTS release and using an older commit doesn't feel good considering the fact that the latest bug fixes are not included.

I am wondering if you have any roadmap for supporting 5.5 ?

In addition to that I tried to install earlier commit 0.0.3 for testing purposes but it requires rinvex/cacheable[dev-develop] which also works only with 5.7

I tried to manipulate my composer.json with below entries, but it doesn't work because it requires the cacheable dev-release.

Any ideas on how to install it on Laravel 5.5 ?

Thanks, Johnson

"rinvex/cacheable": "0.0.2",
"rinvex/laravel-attributes": "0.0.3"

Instalation fails on Laravel 5.5

Hello, the following issue. My Laravel version is 5.5.36. When I try to require the package the output is:

Problem 1
- rinvex/attributes dev-develop requires rinvex/support dev-develop -> satisfiable by rinvex/support[dev-develop].
- Installation request for rinvex/attributes dev-develop -> satisfiable by rinvex/attributes[dev-develop].
- Conclusion: remove laravel/framework v5.5.36
- Conclusion: don't install laravel/framework v5.5.36
- rinvex/support dev-develop requires illuminate/validation ~5.6.0 -> satisfiable by laravel/framework[5.6.x-dev], illuminate/validation[5.6.x-dev, v5.6.0, v5.6.1, v5.6.2, v5.6.3, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9].
- laravel/framework 5.6.x-dev conflicts with laravel/framework[v5.5.36].
- don't install illuminate/validation 5.6.x-dev|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.0|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.1|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.2|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.3|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.4|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.5|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.6|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.7|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.8|don't install laravel/framework v5.5.36
- don't install illuminate/validation v5.6.9|don't install laravel/framework v5.5.36
- Installation request for laravel/framework (locked at v5.5.36, required as 5.5.*) -> satisfiable by laravel/framework[v5.5.36].

I have tried two require the dev-develop version but there is no change. Is the package available for this version of Laravel?

Class name must be a valid object or a string

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

[Enhancement] Allow customizing of tables

Current situation:

It does not matter if you have published the migration files to your usual migrations folder, you can run migrate and you are ready to go. But, if you want to add additional fields to one of those migrations you will have some problems.

  • if you publish the migrations and try to modify and run them, the original migrations from package are migrated first. So you end up in an error "table attributes does already exists".
  • you can modify the migrations in the package, but this is really dirty.

So the only way for me is at the moment to publish the migrations, modify them as I needed them and delete the migrations of your package. But this is also dirty and if I upgrade to a newer version of your package, I will get a message from composer if I want to discard or accept changes (because I deleted your migrations) and after I need to remove them again and look for changes you may have done.

My question is: Could you force the user to publish the migrations and let him migrate on its own? Actually, this is also how a lot of packages do it and not really a downside for the user.

Troubles Seeding Attributes on Entity

Seeing some really strange activity when attempting to seed attributes. I've been able to get it to work, but only when the stars are in alignment and I do the hokey pokey exactly five times while whistling yankie doodle dandy. For the time when running php artisan db:seed was successful, I ran it again immediately without making any other changes and it failed the second time. I can't get it to work anymore. Strange part is, I can get the attributes to save just fine when using php artisan tinker. I'm not sure what's happening other than a potential race condition and/or caching issue.

So, here we start by clearing the cache and then running php artisan db:seed (it does the same thing for php artisan migrate:fresh --seed):

vagrant@homestead:~/Code/app.test$ php artisan cache:clear
Cache cleared successfully.
vagrant@homestead:~/Code/app.test$ php artisan db:seed

...

Seeding: ProductsTableSeeder
Seeding: AttributeSeeder
Seeding: ProductAttributeSeeder

In Connection.php line 664:
                                                                                                                                                                                          
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'cpu-speed' in 'field list' (SQL: update `products` set `cpu-speed` = 1660, `updated_at` = 2018-05-30 14:42:30 where `id` = 14)  
                                                                                                                                                                                          

In Connection.php line 479:
                                                                                      
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'cpu-speed' in 'field list'  

Okay, so we see we have an error when attempting to seed the DB. Let's see if it works in php artisan tinker:

vagrant@homestead:~/Code/app.test$ php artisan tinker
Psy Shell v0.9.3 (PHP 7.2.0-1+ubuntu16.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> $product = App\Product::find(14)
=> App\Product {#2609
     id: 14,

     ...

     created_at: "2018-05-30 14:42:30",
     updated_at: "2018-05-30 14:42:30",
     cpu-speed: null,
   }
>>> $product->{'cpu-speed'} = '1000'
=> "1000"
>>> $product->save()
=> true
>>> $product
=> App\Product {#2609
     id: 14,

     ...

     created_at: "2018-05-30 14:42:30",
     updated_at: "2018-05-30 14:42:30",
     cpu-speed: Rinvex\Attributes\Models\Type\Integer {#2619
       entity_id: 14,
       entity_type: "product",
       attribute_id: 1,
       content: "1000",
       updated_at: "2018-05-30 14:48:47",
       created_at: "2018-05-30 14:48:47",
       id: 1,
     }
   }
>>> 

Yup, it works here. Not sure what's happening with the seeding part. Any ideas?

DatabaseSeeder.php

        $this->call(ProductsTableSeeder::class);
        $this->call(AttributeSeeder::class);
        $this->call(ProductAttributeSeeder::class);

AttributeSeeder.php

use Rinvex\Attributes\Models\Attribute;

        Attribute::create([
            'type' => 'integer',
            'name' => 'CPU Speed',
            'entities' => ['product'],
            //'group' => 'CPU',
        ]);

ProductAttributeSeeder.php

    public function run()
    {
        $product = Product::find(14);
        $product->{'cpu-speed'} = "1666";
        $product->save();
    }

App\Product.php

use Rinvex\Attributes\Traits\Attributable;

class Product extends Model implements HasMedia
{
    use HasMediaTrait;
    use Attributable;
    // Eager loading all the registered attributes
    protected $with = ['eav'];

    ...

Can not override tablename of attribute_entity in config

I'm trying to override the tablenames with the provided config file.
This seems to work for all the tables, except for the attribute_entity table.

When I check the AttributeEntity model, the tablename is hardcoded.

protected $table = 'attribute_entity';

In the other models, like Atribute, the tablename is set dynamically in the constructor.

$this->setTable(config('rinvex.attributes.tables.attributes'));

This means that I cannot override the tablename of the attribute_entity table in the config, even though the config does have an entry for this table:

return [
    'tables' => [
        'attributes' => 'attributes',
        'attribute_entity' => 'attribute_entity',
        'attribute_boolean_values' => 'attribute_boolean_values',
        'attribute_datetime_values' => 'attribute_datetime_values',
        'attribute_integer_values' => 'attribute_integer_values',
        'attribute_text_values' => 'attribute_text_values',
        'attribute_varchar_values' => 'attribute_varchar_values',
    ],
];

Deleting Attributes?

I'm struggling with building a UI for creating, editing, and deleting attributes. Specifically, I'm stuck on deleting the attributes from the entity (product).

I imagine it should be something as simple as a foreach loop to remove/unset all attributes:

    function syncAttributes(Product $product, ProductRequest $request)
   {
        foreach($product->getEntityAttributes() as $key => $value) {
            $product->{$key} = null;
        }
        $product->save();

However, that doesn't work and I'm left with this monstrosity of a solution:

        foreach($product->getEntityAttributes() as $key => $value) {
            $product->{$key} = null;
            $product->save();
            Cache::flush();
            $product = Product::find($product->id);
        }

I'm hoping this is one of those moments where I'm just missing something simple. I could use a hand please!

setAttribute has not been applied, because there are collisions with other trait methods

am trying to use this nice package within nova in combination Spatie\Translatable.

However combining both traits in the model

class myModel extends Model {

    use \Rinvex\Attributes\Traits\Attributable;
    use \Spatie\Translatable\HasTranslations;

}

causes the error

Trait method setAttribute has not been applied, because there are collisions with other trait methods

Is there any way to work around this situation?

Minimum Stability

Will you be upping the minimum stability for this package? Currently relying on dev-develop for a couple of packages

Not available for laravel version 5.5

When I tried to install this package I got this message

Problem 1
- Installation request for rinvex/attributes ^0.0.3 -> satisfiable by rinvex/attributes[v0.0.3].
- rinvex/attributes v0.0.3 requires rinvex/cacheable dev-develop -> satisfiable by rinvex/cacheable[dev-develop] but these conflict with your requirements or minimum-stability.

Then I tried to install rinvex/cacheable I got this

Problem 1
- Installation request for rinvex/cacheable ^0.0.2 -> satisfiable by rinvex/cacheable[v0.0.2].
- Conclusion: remove laravel/framework v5.5.22
- Conclusion: don't install laravel/framework v5.5.22
- rinvex/cacheable v0.0.2 requires illuminate/database ~5.4.0 -> satisfiable by illuminate/database[v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9].
- don't install illuminate/database v5.4.0|don't install laravel/framework v5.5.22
- don't install illuminate/database v5.4.13|don't install laravel/framework v5.5.22
- don't install illuminate/database v5.4.17|don't install laravel/framework v5.5.22
- don't install illuminate/database v5.4.19|don't install laravel/framework v5.5.22
- don't install illuminate/database v5.4.27|don't install laravel/framework v5.5.22
- don't install illuminate/database v5.4.36|don't install laravel/framework v5.5.22
- don't install illuminate/database v5.4.9|don't install laravel/framework v5.5.22
- Installation request for laravel/framework (locked at v5.5.22, required as 5.5.*) -> satisfiable by laravel/framework[v5.5.22].

Default Type Registration and Migrations

Looking at 622dfdd#diff-ea0d11a7ac5ac10f344772d0863e113d, I'm wondering that if this is considered implementation details, why force the migration of these default types as well? It'd be nice to somehow give the developer an option of opting out of the core type migrations. Would it be better to provide an artisan command to publish (or copy) the core type migration files to the project's database/migration folder instead of loading from the AttributesServiceProvider?

Perhaps we move the core type migration files to the directory .../database/core-type-migrations. This way, the following line of code will only load the necessary tables:

         // Load migrations
         ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');

Then, if the user wants to implement the default core types, they could run php artisan vendor:publish or php artisan rinvex:publish:attributes.

ValueCollection not saving values

I'm having trouble working with the ValueCollection. The documentation doesn't help because it doesn't specify in any way how the ValueCollection is supposed to be used for multi-value attributes other than how to store the values with push() and add(). I thought it'd work by creating a custom attribute but instead of Value it'd instance ValueCollection but Laravel throws an undefined Relation error. Can you help with undestanding the ValueCollection?

Call to a member function add() on null

I have created attribute "conditions", and attach values.

$advert = \App\Models\Advert::find(400);
$advert->conditions->add(['value1', 'value2']);

Call to a member function add() on null

Installation Failed On Laravel 5.2

Hello,
I have used composer require rinvex/cacheable dev-develop but it won't install!

getting this error:

Problem 1
- Installation request for rinvex/attributes dev-develop -> satisfiable by rinvex/attributes[dev-develop].
- rinvex/attributes dev-develop requires rinvex/cacheable dev-develop -> satisfiable by rinvex/cacheable[dev-develop] but these conflict with your requirements or minimum-stability.

Support for 5.7?

I recently found out about this repo as it fits a need we have with a system we are building. However, we are on 5.7, and while I've started to fork everything to test it, I can't see that being the resolution long term. I was wondering how often do you guys update when laravel releases a new version?

Thanks,

Jesse

Getting Started Frustrations with Laravel 5.6

Having a lot of struggles getting this working with Laravel 5.6. I was able to get the installation going alright after adding "minimum-stability": "dev" to composer.json. I was also able to create a seeder to populate some attributes:

      use Rinvex\Attributes\Models\Attribute;

       Attribute::create([
           'type' => 'varchar',
           'name' => 'CPU',
           'entities' => ['App\Product'],
           'group' => 'Core Components',
       ]); 

I can verify the attribute is in the DB okay and the slug is set to 'cpu' (and group is set to 'core-components', which is another issue for another time).

In AppServiceProvider.php, I've pushed the entity...

        // Push your entity fully qualified namespace
        app('rinvex.attributes.entities')->push(\App\Product::class);

Now, when it comes time to actually set an attribute value for the product entity, it doesn't just work as it says in the documentation.

>>> $product = App\Product::find(14)
=> App\Product {#1007
     id: 14,
     ....
>>> $product->cpu = 'ARM';
=> "ARM"
>>> $product->save()
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'cpu' in 'field list' (SQL: update `products` set `updated_at` = 2018-04-27 11:06:21, `cpu` = ARM where `id` = 14)'
>>>

Assuming I get through this issue, the next issue is what happens when I need to set a field with a space in the name like "CPU Speed"? The slug comes out to be "cpu-speed". Does this mean I use $product->cpu_speed or $product->cpuSpeed or what?

Assuming I get through that issue, what about grouping? I need to be able to display the group in a human friendly way. For example "Core Components" instead of "core-components". I'll also need to provide a way for an admin to create new groups, set an order for each group, etc. Seems to me like another table such as "AttributeGroups" would be better, and set attributes.group to a foreign key instead of a slug. Documentation around grouping would be much appreciated.

But first, let's get through setting a value for the attribute please! What did I miss?

Using multiple where-clauses

Hi!

Is it possible to user multiple where clauses on entities using attributes? Like so:

$users = App\Product::where(
    ['color','=','black'],
    ['power', '>','200'],
    ['max_speed','>','260']
)->get();

Thanks in advance!

EAV values empty

Soo @Omranic.

I followed your steps and created a new laravel project and I am still unable to get the data.
Here is the link to the repo:
https://github.com/psychonetic/laravel-attributes

Just migrate the database, run php artisan serve and hit the following url:
localhost:8000/api/articles.

A size attribute is created, after an article and also applied the size to the article and finally I try to get the result. But as already discussed in #26 the size is always null.

Best regards,

Marco

installation failed

Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for rinvex/attributable ^0.0.1 -> satisfiable by rinv
ex/attributable[v0.0.1].
- rinvex/attributable v0.0.1 requires rinvex/cacheable dev-develop -> satisf
iable by rinvex/cacheable[dev-develop] but these conflict with your requirements
or minimum-stability.

Installation failed, reverting ./composer.json to its original content.

Class name must be a valid object or a string

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.

getEntityAttributes Error

hello
When using the package, I get the following error

rinvex\attributes\src\Traits\Attributable.php on line 178

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."$en"' asc' at line 1 (SQL: select * from attributes where 0 = 1 order by sort_order asc, name->'$."$en"' asc)

Documentation example error, attribute field code

Issue reported by @cmarfil here https://github.com/rinvex/sparse/issues/9

Hello,

In the documentation there is the following example to create an attribute.

Attribute::create(['code' => 'size', 'name' => ['en' => 'Product Size'], 'type' => '\Rinvex\Sparse\Models\Data\Varchar', 'entities' => ['App\Models\Company', 'App\Models\Product']]);

But, the "code" field is not used in the Attribute model:

Attribute.php:

    protected $fillable = [
        'name',
        'slug',
        'description',
        'order',
        'group',
        'type',
        'entities',
        'collection',
        'default',
    ];

So, if code field is not used, how can I save the value of a simple attribute?
I think there is a need to clarify this point in the documentation.

This would not work:

Attribute::create(['code' => 'size', 'name' => ['en' => 'Product Size'], 'type' => '\Rinvex\Sparse\Models\Data\Varchar', 'entities' => ['App\Models\Company', 'App\Models\Product']]);

$company = App\Models\Company::find(1);
$company->size = '123';
$company->save();

Thanks,
Regards.

Custom options attribute

I was thinking about adding a options JSON like column into the attributes table (or maybe into attribute_entity?) so it could store some extra information about the attribute that can be used to customise the attribute behaviour in the application.

From the package point of view, it would just be a write/read column, so no extra coding needed.

We can se an example of a practical usage (field options):

screen shot 2018-06-19 at 12 53 49

Thoughts?

php artisan migrate --path="vendor/rinvex/attributable/database/migrations" ERROR!!

run

php artisan migrate --path="vendor/rinvex/attributable/database/migrations"

show error:

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: create table `` (id int unsigned not null auto_increment primary key, `slug` varchar(255) not null, `name` json not null, `description` json null, `sort_order` mediumint unsigned not null default '0', `group` varchar(255) null, `type` varchar(255) not null, `is_required` tinyint(1) not null default '0', `is_collection` tinyint(1) not null default '0', `default` text null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate utf8mb4_general_ci)

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ''

Why? thk!!!

Gathering Attributes for Specified Entity

Is there a way to filter out the attributes that are tied to a specified entity?

To get a list of all attributes, we have:

$attributes = Attribute::all()

But, what if we just want attributes that belong to an entity, like this:

$partAttributes = Attribute::entities('part')->all();
$productAttributes = Attribute::entities('product')->all();

Similar to $product->getEntityAttributes(), but without needing to fetch an entity first. Any hints?

Upgrade to v0.0.6 from v0.0.4: "Class name must be a valid object or a string"

I'm getting this error I can't seem to shake after upgrading from v0.0.4 to v0.0.6 on Laravel 5.6. It happens when I attempt to load an entity using $product = App\Product::find(1);. This happens using php artisan tinker as well as in the browser.

Class name must be a valid object or a string

Stack trace isn't very helpful to me:

1 Symfony\Component\Debug\Exception\FatalThrowableError 
…/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php656
0 {main}
…/public/index.php0

I've attempted to use the following commands and try again, but the error is persistent:

php artisan cache:clear
php artisan clear-compiled
composer dump-autoload

In the meantime, I'm downgrading to v0.0.4. Any help would be appreciated.

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

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

/** * Create a new Eloquent Collection instance. * * @param array $models * @return Rinvex\Attributes\Support\ValueCollection */ public function newCollection(array $models = []) { return new ValueCollection($models); }

Get this
image

JSON column compatibility between MySQL and MariaDB

default

My code

        $company = Company::find(1);
        var_dump($company->size);

Code where error. \vendor\rinvex\attributes\src\Traits\Attributable.php

static::$entityAttributes->put($morphClass, app('rinvex.attributes.attribute')->whereIn('id', $attributes)->orderBy('sort_order', 'ASC')->orderBy("name->\${$locale}", 'ASC')->get()->keyBy('slug'));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.