question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`pivotFields` functionality broken

See original GitHub issue

So I saw that there is an undocumented feature for adding additional data to pivot columns here:

https://github.com/Laravel-Backpack/CRUD/blob/57666443a1c4db57a76470d0876dac9cbab6ced9/src/PanelTraits/Create.php#L86-L92

if (isset($field['pivotFields'])) {
    foreach ($field['pivotFields'] as $pivotField) {
        foreach ($data[$pivotField] as $pivot_id =>  $field) {
            $model->{$field['name']}()->updateExistingPivot($pivot_id, [$pivotField => $field]);
        }
    }
}

Looks like the reason for this is that you’re referencing $field['name'] on line 89, even though the $field variable has been overwritten inside of the current (nested) foreach.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tabacitucommented, Oct 25, 2017

Fixed on dev. Thank you @hewok for the PR! Cheers!

0reactions
hewokcommented, Oct 4, 2017

Hi @lloy0076 , no, there is not PR for the bug. [EDIT]: @lloy0076 I’ve created PR.

Hi @tabacitu , I’ve changed the $value of the for loop, exactly the “$pivot_field”. The problem is the variable $field (now, on master branch) on line 99 will be overwritten by for loop on line 106

https://github.com/Laravel-Backpack/CRUD/blob/6e31f985e902bd8d0b5891db143cad8d79427e6e/src/PanelTraits/Create.php#L99-L111

When try to save the page, where I’ve used the addField functionally, I received the error:

Illegal string offset ‘name’

because $field[‘name’] (on line 107) is not the correct field name.

If anyone want to try (you need to update some info 😉 ):

$this->crud->addField([
      'label' => "Element list",
      'type' => 'block_weight',
      'name' => 'blocks', // the method that defines the relationship in your Model
      'entity' => 'block', // the method that defines the relationship in your Model
      'attribute' => 'title', // foreign key attribute that is shown to user
      'model' => "App\Models\Block", // foreign key model
      'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
      'pivotFieldsLabel' => ['Weight'],
      'pivotFields' => [
            'weight'
      ],
]);

I hope I’m making myself clear.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Troubleshoot and Fix Excel Pivot Table Errors
How to troubleshoot and fix Excel pivot table errors, such as PivotTable field name is not valid. Find the problem, and fix it....
Read more >
vba - Pivot Table: Detect When Pivot Field is Collapsed
I've been looking for a way to detect if ALL of the second position row fields are collapsed/hidden/invisible/not-drilledTo in order to identify ...
Read more >
VBA PivotFields.Name returning incorrect result : r/excel - Reddit
It worked until I had to add a new field to the values, and then it broke in the strangest way. Sub test()...
Read more >
How to Troubleshoot Pivot Items Missing From Excel Pivot Table
Expand the Pivot Fields · Select one of the pivot items in the outermost pivot field (Region). · On the Excel Ribbon, click...
Read more >
Use the Field List to arrange fields in a PivotTable
Rearrange fields in your PivotTable (pivot table) by using the Field List, and show the Field List again when it disappears.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found