Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

select_multiple works, select2_multiple don't #26

Closed
f-liva opened this issue Jun 6, 2016 · 7 comments
Closed

select_multiple works, select2_multiple don't #26

f-liva opened this issue Jun 6, 2016 · 7 comments
Labels
Milestone

Comments

@f-liva
Copy link
Contributor

f-liva commented Jun 6, 2016

When I try to use a select2_multiple field instead of a select_multiple field, I get this error:

ErrorException in b58d2ac85e3cfb89e50920aa215a69bd96d9acac.php line 25: Array to string conversion (View: D:\Progetti\instalmec.it\Instalmec\vendor\backpack\crud\src\resources\views\fields\select2_multiple.blade.php) (View: D:\Progetti\instalmec.it\Instalmec\vendor\backpack\crud\src\resources\views\fields\select2_multiple.blade.php) (View: D:\Progetti\instalmec.it\Instalmec\vendor\backpack\crud\src\resources\views\fields\select2_multiple.blade.php)

I changed nothing else the field type, from select_multiple to select2_multiple

@tabacitu
Copy link
Member

tabacitu commented Jun 6, 2016

That's very odd, I've just tested and it works perfectly for me. I've even used it in PageManager.

Here's my syntax:

$this->crud->addField([       // Select2Multiple = n-n relationship (with pivot table)
                                'label' => "Tags",
                                'type' => 'select2_multiple',
                                'name' => 'tags', // the method that defines the relationship in your Model
                                'entity' => 'tags', // the method that defines the relationship in your Model
                                'attribute' => 'name', // foreign key attribute that is shown to user
                                'model' => "Backpack\NewsCRUD\app\Models\Tag", // foreign key model
                                'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
                            ]);

What's yours?

@tabacitu
Copy link
Member

tabacitu commented Jun 6, 2016

Also, have you defined your relationships on your models? That might be the issue.

@f-liva
Copy link
Contributor Author

f-liva commented Jun 6, 2016

App\Http\Controllers\Admin\ProductCrudController

$this->crud->addField([
    'label'     => 'Tags',
    'type'      => 'select2_multiple',
    'name'      => 'tags',
    'entity'    => 'tags',
    'attribute' => 'name',
    'model'     => 'App\Models\Tag',
    'pivot'     => true,
]);

App\Models\Product

public function tags()
{
    return $this->belongsToMany('App\Models\Tag');
}

App\Models\Tag

public function products()
{
    return $this->belongsToMany('App\Models\Product');
}

The strange is that the normal select works, it is only the select2 that doesn't.

@crameep
Copy link

crameep commented Jun 13, 2016

Same exact issue. I notice the Select2 Multiple works until I add tags, then it breaks with
ErrorException in d7929459cb7e413954346700e4814b9d913f1d39.php line 25:
Array to string conversion (View:

@f-liva
Copy link
Contributor Author

f-liva commented Jun 13, 2016

Maybe some directive for tags is hard coded in the CRUD core and goes in conflict?

@tabacitu
Copy link
Member

EUREKA! Who knew it was a mistake that small? :-)
You were testing on PHP 7, I was not.

@f-liva
Copy link
Contributor Author

f-liva commented Jun 14, 2016

Magic happens switching to PHP 7! 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants