sunel / eav

Entity–attribute–value model (EAV) for Laravel Artisan
https://sunel.github.io/eav/
143 stars 39 forks source link

How to retrieve one model with all attribute values. #3

Closed RadoslavAngelov closed 6 years ago

RadoslavAngelov commented 6 years ago

Hello,

how can you take a model instance with all its attribute values. For example I have Product with attribute name. If I want to update the value of name I can make:

`$product = Products::find(1);

$product->name = 'Not a Flamethrower';

$product->save();`

but how can I display $product->name. If i try to dd($product->name) the result is null

sunel commented 6 years ago

As you can the name is a attribute , its not the member of the main table, so while retrieving the name, you need to tell the system that to include it

Products::where('id', 1)->get('*', 'name');

* -> to get all the values from the main table and name attributes to be included.

To retrieve all the attribute values check this link

Quick View

Products::where('id', 1)->get('attr.*');

Let me know if you find any issue understanding this, i am trying make the documentation more clear.

RadoslavAngelov commented 6 years ago

Yes, thank you this works.