Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.15k stars 891 forks source link

1:n relation - models with translations: "Collection::setLocale does not exist" #1332

Closed axelzuzek closed 6 years ago

axelzuzek commented 6 years ago

Bug report

I have 2 models newsarticle and newscategory connected 1:n, both models use "hasTranslations"

Since upgrading backpack crud to "^3.4.0" and laravel 5.6 the crud edit operations create and update throw the following error: "BadMethodCallException Method Illuminate\Database\Eloquent\Collection::setLocale does not exist."

When I remove the 1:n relation from newsarticle Crud controller: $this->crud->addColumn([ 'name' => 'newscategory_id', 'label' => __('admin.News_Category'), 'type' => "select", 'entity' => 'newscategory', 'attribute' => "name", 'model' => "App\Models\Newscategory", ]); the error disappears.

What I did:

Upgraded Backpack/Crud from 3.3 to 3.4 Upgraded Laravel from 5.5 to 5.6

Backpack, Laravel, PHP, DB version:

"php": ">=7.1.3", "backpack/MenuCRUD": "^1.0", "backpack/base": "^0.9.0", "backpack/crud": "^3.4.0", "backpack/langfilemanager": "^1.0", "backpack/pagemanager": "^1.1", "laravel/framework": "5.6.*", "laravel/tinker": "~1.0", "laravelcollective/html": "^5.6", "spatie/laravel-translatable": "^2.1", "themsaid/laravel-langman": "^1.3", "webpatser/laravel-countries": "dev-master"

tabacitu commented 6 years ago

Hi @axelzuzek ,

I just merged PR #1330 , which should fix it for you. Let me know if that's not the case, after a composer update.

Cheers!