0
votes

im trying to get all available properties and their contents, if there any, by item. I dont know exactly how to describe it..

One Item belongs to a group. One Group can have multiple categories.
One Category can belong to multiple groups and can have multiple properties.
One Property has one category
One PropContent belongs to one item and property.

How do i get all properties available for a category with potential prop_contents by item ?

Table example:

items groups categories group_categories item_prop_contents category_props
id id id group_id id id
name name name category_id category_prop_id category_id
group_id item_id name
content type (text,bool,int)
class Item extends Model
{
    public function group()
    {
        return $this->belongsTo(Group::class);
    }

    public function contents()
    {
        return $this->hasMany(ItemPropertyContent::class);
    }
}
class Group extends Model
{
    public function categories()
    {
        return $this->hasManyThrough(Category::class, 'group_categories');
    }

    public function items()
    {
        return $this->hasMany(Item::class);
    }
}
class Category extends Model
{
    public function groups()
    {
        return $this->belongsToMany(Group::class);
    }

    public function properties()
    {
        return $this->hasMany(CategoryProperty::class);
    }
}
class CategoryProperty extends Model
{
    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function item()
    {
        return $this->belongsTo(Item::class);
    }

    public function contents()
    {
        return $this->hasMany(ItemPropertyContent::class);
    }
}
class ItemPropertyContent extends Model
{
    public function property()
    {
        return $this->belongsTo(CategoryProperty::class);
    }

    public function item()
    {
        return $this->belongsTo(Item::class);
    }
}

I know it is maybe not perfectly explained, but i dont know how to name it.

I appreciate any help. Thanks!