Comments (1)
I've found a workaround.
When you add the optionsLabel method, the title function is no longer used as id when saving.
The title function is still used for display in the field's selection list, but you're limited to a single attribute-name for the display of the selected models.
Also the hideSelected functionality will fail, as the title and label differ.
However, it is still possible to use a custom label.
Here's what I did to make this possible:
In the related BelongsTo model:
Add a name for a custom attribute to the appends array:
protected $appends = [
'yourAttributeName'
];
Create an accessor for this attribute:
public function getYourAttributeNameAttribute()
{
// return the custom label, in my case:
return $this->id . ':: ' . $this->name;
}
In the Nova Resource, add the optionsLabel method:
BelongsToManyField::make('Products', 'products', Product::class)
->optionsLabel('yourAttributeName'),
In the related BelongsTo Resource (Optional):
edit the title function for consistency
public function title() {
return $this->IdName;
}
from belongs-to-many-field-nova.
Related Issues (20)
- Depends on would'nt show when the key has value
- Nova 4 support HOT 2
- Add Nova 4 support HOT 2
- Showing wrong title HOT 1
- undefined getting on self class relationship
- No dark mode support?
- JsonSerialize method not compatible HOT 1
- No(t working) option to preset options while creating
- When 3.0 is going to release? HOT 1
- Replication support
- Routes are missing from vendor files
- Name field rendering problem in version 4.26 HOT 8
- Field not rendered with Nova 4.33 HOT 1
- getHelpText does not exist HOT 4
- Support for spatie/laravel-translatable HOT 1
- Inadequate Search Space HOT 1
- Rules are not respected HOT 2
- Updating a model empties my BelongsToMany field
- While updating data if i change fleet type option and then selected parent category option which is not belongs to fleet type then also can save data without any error. It should not allow to save or if i change fleet type then selected parent category should remove so can select other options which is related to that fleet type.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from belongs-to-many-field-nova.