how adding a fields to relationship Table in pivot table method using laravel - laravel-4

I want to design an online store. For each category of productions, we would have its own fields.
Connections between tables of fields and categories are done and displayed in the part of registration of productions.
At the end, the value of each field should be stored that it should contains the related table between table of fields and productions (in addition to/plus/+) the value of that field.
My problem is in this part and I want that this related table has an additional field that I could value it.
In the following figure, the picture of table and my connections are shown, if there is (any problem/ something wrong with it), I would appreciate you to help me.
View Relationship Images :
http://ir-up.ir/uploads/1416568805731.jpg

You'd simply need to add a withPivot when declaring the relationship:
return $this->belongsToMany('Role')->withPivot('foo', 'bar');
Extra attributes in pivot tables are covered in the docs, here - http://laravel.com/docs/4.2/eloquent#working-with-pivot-tables

Related

Is it possible to use inline_create with pivot fields with Laravel Backpack?

Is it possible to use Laravel Backpack relationship field type with both inline_create and pivot fields enabled?
I'm trying to make this happen:
I have 2 entities, Products and Productions, and both have a belongsToMany relation defined in the model. Therefore they have a pivot table with product_id and production_id.
In this pivot table I have a count column.
With Backpack I'm trying to solve the following:
I want to fetch products on productions create operation, or create product from this view and specify the pivot field count with it.
If I remove the 'subfields' property from the field definition, the add field button shows up.
I've attached 3 screenshots of the mentioned functionality.
Product with Add, but without count field
Clicked on "Add" - Modal opened
Product with count pivot field and without Add
Hello #roamingTurkey !
You should be able to do it, but you need to configure your pivotSelect key in your n-n field definition : https://backpackforlaravel.com/docs/5.x/crud-how-to#extra-saving-additional-attributes-to-the-pivot-table
Let me know!

How to use field of pivot table

I've two tables user and product, along with their relationship user_product. The relationship table contains an extra field category. Now I want to find
the number of products selected by a user of a particular category.
I've done it in my page through coding. Is there any easier way to do this?
How to use field of pivot table?
you can use withPivot
Ex:
$this->belongsToMany('Role')->withPivot('foo', 'bar');

What table holds the category selections for the time_card table in ServiceNow

I'm using the ODBC connector to query time card data from the time_card table in ServiceNow, and there are two columns I'm wondering about: category and dv_category - those two fields are pulled from somewhere, and I do not know where. Is there are table that holds these values, or are they static on the UI and passed through?
The 'category' field is just a string(40) with a Choice List local to the field. So, it's not a reference field, just a drop down. The Choice List can be modified
I'm not finding the 'dv_category' field on the time_card table and I'm on Helsinki Patch 3. Can you clarify?
Editing to add the actual answer to the question : 'I believe the table you're looking for is called 'sys_choice''

How to store different type and number of fields in one database table?

Hello everybody I'm making a "Bulletin board", like this: http://stena.kg/ad/post, I'm using Laravel 5.0, and don't know how to store different fields in database table, for example if I choose "Cars" category I should to fill Mark, Model, Fuel (etc fields for cars category), If I choose Flats category I should fill fields like Area, Number of rooms etc...How to organize all of this? I tried some ideas but nothing helped me(
Try to save data as json in table. Parse json format to string and save it in db, but it will cause many problems in future, so not recommend that solution. I recommend to store data in separate tabels, each one for category. For optimise process it is possible to create catregory table, and category_item table with fields like name, description and so on. Different category demands sp=ecific fields, so best solution is to create table per category.

GAS ORM many-many relation with attributes

I'm using CodeIgniter and I'm starting to work with gas orm.
One of my m-n-relationship-tables using a composite key has also some additional attributes to the releation.
For Example:
Table teams, Table employees, and a m-n table which binds them together + adding the attribute role
Is it possible to get the attribute using GAS ORM?
Yes, it is possible.
Simply create a new relationship in one of the two tables you are going to link with the pivot table that refers to the pivot table itself as a has_many relation. (But dont do the linking stuff in the model file, eg:
ORM::has_many('\\Model\\User\\Role')
instead of
ORM::has_many('\\Model\\User\\Role => \\Model\\Role')
See http://ellislab.com/forums/viewreply/1050559/ for exact the same question.

Resources