After upgrade to backpack v4.1 when use attribute type of model function for column, it does not work actually.
Column definition:
$this->crud->addColumn([
'type' => 'select',
'name' => 'id_outlay_center',
'label'=> trans('backpack::nou.outlay_center'),
'entity' => 'outlayCenter', // the method that defines the relationship in your Model
'attribute' => "outlay_center_with_code", // foreign key attribute that is shown to user
'model' => "App\Models\Codelist\OutlayCenter", // foreign key model
]);
Attribute "outlay_center_with_code" is calculated in model like this:
App\Models\Codelist\OutlayCenter {
public function getOutlayCenterWithCodeAttribute() //outlay_center_with_code
{
return $this->code . ' - ' .$this->title;
}
}
Attributes work only with fillable fields, not calculated like getNameAttribute().
??
It worked in v4.0
??
Does not work in v4.1
??
??
When I run php artisan backpack:version the output is:
PHP 7.2.10 (cli) (built: Sep 13 2018 00:48:27) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
v7.10.3@6e927e78aafd578d59c99608e7f0e23a5f7bfc5a
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:
backpack-for-laravel tag;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
Hello @potocky
Do you have outlay_center_with_code in $appends on your model ? Could you add it and check again ?
I added appends variable to the model:
protected $appends = ['outlay_center_with_code'];
It works ! Thank You!
Nice... banged my head for 1 hour trying to understand what I missed during Laravel7/BP4.1 upgrade ;-)
Already documented? Couldn't find this anywhere.
Not yet @dividy and so sorry for making you went to all that trouble :(
I'm trying to figure out if we should add support for acessors directly instead of asking users to use the $appends property.
For now $appends is a temporary solution, or we add direct support for it, or we document it.
I am thinking the best would be to add direct support for it and avoid that extra step for our users as we already do in other places.
For now I am glad you find this issue and it solved your problem.
I will ping you guys here ASA we implement the final solution.
Best,
Pedro
I had the same problem and found reference in the following Pedro's comment: https://github.com/Laravel-Backpack/CRUD/pull/2732#issuecomment-624566624
It's ok, now that I know it.
Maybe you could document it in the Models section of the upgrade guide.
Have a nice day!
I also had trouble updating, what I did was add in the field in the $fillable variable of the model
Ugh. Sorry for the frustration guys!
I wonder why we didn't need $appends in 4.0, but we do in 4.1. Any idea @pxpm ? Any way to make it work again with no $appends? I assume it's just a matter of how we get/call the accessor on the model?
Hello guys, once again sorry for the frustration of running into this error.
I'v submited #2815 that will allow to use mutated attributes without adding them to appends, just like it was back in 4.0.
Once again, sorry for inconvenience.
Going to close this so we keep any discussion in PR thread.
If possible could you test the solution provided in #2815 and give feedback there ? It would be awesome .
Best,
Pedro
Most helpful comment
Hello guys, once again sorry for the frustration of running into this error.
I'v submited #2815 that will allow to use mutated attributes without adding them to appends, just like it was back in 4.0.
Once again, sorry for inconvenience.
Going to close this so we keep any discussion in PR thread.
If possible could you test the solution provided in #2815 and give feedback there ? It would be awesome .
Best,
Pedro