-
Notifications
You must be signed in to change notification settings - Fork 893
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
[Bug] Can't change the model attribute when using "relationship" crud field on create crud #5252
Comments
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:
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! -- |
Sounds like it's really similar to the following issue #5220 |
Hey @Astriel If you need an attribute in a select field (as subfield) you should define the attribute in the subfield. There is no point in defining the attribute in the "parent field" as it will not apply to any subfield. From what you shared I am guessing you are working with pivot fields, in that case, you should set the attribute in the I am going to close this as I don't think there is any bug here. Conversation is not locked, if you think I am wrong (and I am wrong a lot of times) please reply, and if needed we will re-open. Cheers |
Hey @pxpm ! Actually the attribute is not for the subfield. The attribute parameter is for the main field. I'm using the pro plugin and the "relationship" type of input. In my case, I've got a n - n relationship and I want to add several models of one entity to another one. If I'm defining the crud field (not a subfield) with the following code, and I pass the attribute parameter, it works well :
But as soon as start to add subfields to fill pivot values like on this demo page : https://demo.backpackforlaravel.com/admin/monster/create#relationship the 'attribute' is not longer taken in account, and it's going to fetch for the "name" attribute on my model and not "version". |
Like I said to you, and pointed in the last comment. In a n-n relationship, you should configure the attribute in your CRUD::field([
// adding here for clarity:
'pivotSelect' => [
'attribute' => 'version'
]
'name' => 'myrelation',
'type' => 'relationship',
'tab' => __('backpack.ats'),
'model' => 'App\Models\V0\Mymodel',
'label' => __('backpack.firsttab'),
'pivot' => true,
'subfields' => [
[
'name' => 'first_field',
'label' => __('backpack.first_field'),
'type' => 'text',
'tab' => __('backpack.firsttab'),
'hint' => __('backpack.first_field_hint'),
'wrapper' => [
'class' => 'form-group col-md-6',
],
],
],
]); Let me know if that doesn't help. Thanks 🙏 |
Sounds perfect ! Problem solved, thank you so much. Just a quick last question, my model name is "ats". I've defined the |
Can you provide a screenshot or something of what you mean ? My guess is that when you Let me know! 🙏 |
Bug report
What I did
I've generated a CrudController with the
php artisan backpack:build
commandOn the CrudController, in the
setupCreateOperation
method, I've set a "relationship" field which is corresponding to a many to many relation. This works fine and I'm able to select it on the screen, but when I want to change the "attribute" to showcase another value from my model it's not working.What I expected to happen
With the following code and the following field define, I would expect to have the "version" attribute used into the select input generated with the crud.
What happened
Whatever I try, the CRUD field is always going to fetch for the "name" attribute of my model.
What I've already tried to fix it
I've already tried to switch to other fields such as
Is it a bug in the latest version of Backpack?
After I run
composer update backpack/crud
the bug... is it still there?Yes
Backpack, Laravel, PHP, DB version
When I run
php artisan backpack:version
the output is:The text was updated successfully, but these errors were encountered: