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

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!

Related

Quicksight Filter Option

I am trying to create one dashboard where I am using a pivot table in my visualization. I want one of the dashboard filter should not be applied to one column of the pivot table. For ex- I have my filter as Product and I have different amount value in the pivot table. I do not want that product filter to be applied to target amount column as back in my database it has been assigned to one of the 7 products used in the filter,If the filter will change to another product that target amount will change but I want that target value to remain intact. Please Please help

make the display order based on another table value

I have two tables request and status_tracker. I want to list the row in top which has only one entry in status tracker.
I have the query in $user=DB::table('request')->select('request.*)->get();
I want to add the order based on status_tracker table. If request_id has count '2' in status_tracker table I want to display in top of the table
$user=DB::table('request')->select('request.*)(order may happened here)->get();
if ID 19,11,15 has 2 count in status_tracker it should display first and rest of them will display below as 19,11,15,18,17,16,14,13,12,10.
Is it possible by order the row based on another table field count in laravel?
You could use 'withCount' which will add a column named {relation}_count and orderBy with that, so try something like this:.
$user = App\Request::withCount('status_tracker')
->orderBy('status_tracker_count', 'desc')
->get();
You can read more about this on official Laravel docs
Note: Your model relationship should be well established in order for this to work, so make sure you have specified the relations between both tables :D

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');

How to get most repetitive values with Eloquent?

I have relation many to many (posts and tags) in Eloquent. Is it possible to order tags in the pivot table to get 10 most commonly used tags?
Yes it is possible, add some kind of attribute (to the pivot table and update it upon every select from the database. (increment the value)
And when selecting use wherePivot method.
If you want "most recent used", add timestamps to the pivot table in your migration and touch pivot table on every select.
Yes it is actually very simple to do that.
In the table that you store your tags add another column called count_cache(or whatever you want), then every time you add a tag instance to a post instance do a count() of the tag_id in the pivot table and store the value to the count_cache column in the tags table.
Then you can simply get the tags table ordered by the count_cache collumn (descending) with a limit of 10.
If you need further explanation please make a comment :)

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

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

Resources