Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Checklist error with pluck #3035

Closed
vamsi381 opened this issue Jul 16, 2020 · 4 comments
Closed

Checklist error with pluck #3035

vamsi381 opened this issue Jul 16, 2020 · 4 comments
Assignees

Comments

@vamsi381
Copy link

In my crud controller, There is one field called "roles (Multiple checklist)", While before saving the roles, I am converting array into string like 1,2,3 using implode. Ex: CrudController setUp() method

$options = [
                'name' => 'roles',
                'label' => 'Roles',
                'type' => 'checklist',
                'entity' => 'roles',
                'attribute' => 'name',
                'model' => "Backpack\PermissionManager\app\Models\Role",
            ];
        $this->crud->addField($options);

In Store method,

public function store(StoreRequest $request)
    {
        $sel_roles = $request->input("roles");

        $roles = !empty($sel_roles) ? implode(",",$sel_roles) : "";

        $request->request->set("roles",$roles);       

        //dd($request);
        return parent::storeCrud($request);
    }

Edit Method looks like this,

public function edit($id) {

        $this->crud->hasAccessOrFail('update');
        // get the info for that entry
         $this->data['entry']= $this->crud->getEntry($id);
         $options = [
            'name' => 'roles',
            'label' => 'Roles',
            'type' => 'checklist',
            'entity' => 'roles',
            'attribute' => 'name',
            'model' => "Backpack\PermissionManager\app\Models\Role",
        
        ];
    
        $this->crud->addField($options);

         $this->data['crud'] = $this->crud;
         $this->data['fields'] = $this->crud->getUpdateFields($id);

         $this->data['id'] = $id;

         return view('crud::edit', $this->data);

    }

If am trying to access, Edit page, I am getting below error,

ErrorException in line 15: Call to a member function pluck() on string (View: /var/www/html/app/vendor/backpack/crud/src/resources/views/fields/checklist.blade.php)

@welcome
Copy link

welcome bot commented Jul 16, 2020

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - Github Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

@pxpm
Copy link
Contributor

pxpm commented Jul 17, 2020

Hello @vamsi381

Sorry but i cannot follow your issue.

What's the output of php artisan backpack:version ?

Line 15 does not have any pluck, my guess is that is related with line 17 where we have:

 if ($field['value'] instanceof Illuminate\Database\Eloquent\Collection) {
    $field['value'] = $field['value']->pluck($key_attribute)->toArray();
  }

So that pluck will only be called if the field value is a collection, if it's a string we don't call.

My guess is that you are using an outdated version, that might have that bug layin' around.

Let me know.

Pedro

@pxpm pxpm changed the title [Bug] Checklist error with pluck Jul 17, 2020
@vamsi381
Copy link
Author

Hi @pxpm ,

Thank you very much.
I am sending the value in the collection format, Now the checkbox lists are displaying again in the edit page.

Thank you.

@pxpm
Copy link
Contributor

pxpm commented Jul 17, 2020

Nice to know @vamsi381

Best,
Pedro

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants