Hello @aurawindsurfing,
thanks for your reply. As I thought, I will have to explain specifically what effect I would like to achieve :-D
Imagine that we have two models:
Product (table: products)
basic fields that currently exist in this table:
['name', 'slug', 'price_netto', 'price_brutto', 'desc', 'short_desc', 'image']
and Page (table: pages)
basic fields that currently exist in this table:
['author_id', 'active', 'layout', 'name', 'slug', 'short_desc', 'desc', 'image'];
I launch CMS on production server for my customer. And I want to give him ability to extend thes models with additional fields without digging in into code and sql. So I create a controller where he chooses to what model he wants to add an additional field, so structure looks like this:
additional_fields
+------+------------+----------+--------------+-------------------------------+
| id | table_name | type | key | desc |
+------+------------+----------+--------------+-------------------------------+
| 1 | product | text | field1 | First test field for product |
| 2 | product | text | field2 | Second test field for product |
| 3 | pages | textarea | rick_roll | First test field for page |
| 4 | pages | checkbox | page_lalalla | Second test field for page |
+------+------------+----------+--------------+-------------------------------+
And now, while editing single product in admin panel you will have all "base" fields, and section with additional fields. I think that it should render like this:
@foreach($product->additional_fields() as $additional_field)
<div class="form-control">
<label for="{{$additional_field->key}}">{{$additional_field->desc}}</label>
<input type="{{$additional_field->type}}" value="{{$additional_field->value}}" />
</div>
@endforeach
Then customer puts some values into previously created additional fields:
additional_fields_values
+-----+-----------+-----------+---------------------------------+
| id | field_id | model_id | value |
+-----+-----------+-----------+---------------------------------+
| 1 | 2 | 55 | Field value for Product (id:55) |
| 2 | 4 | 3 | Field value for Page (id:3) |
+-----+-----------+-----------+---------------------------------+
And it should return all additional_fields related only with "products" table and show inserted values, so in this particular case (edit product with id: 55) we should render two fields:
<div class="form-control">
<label for="field1">First test field for product</label>
<input type="text" value="(null)" />
</div>
<div class="form-control">
<label for="field2">Second test field for product</label>
<input type="text" value="Field value for Product (id:55)" />
</div>
I don't want to extend base table for these fields because it will be quite complicated when using Dimsav translatable package and it will also bring problems while pushing updates because every customer will have different fields in their base tables.
Is it even able to do? Maybe you can suggest me some other way to acheive similiar effect in less painful way?