Closed YarinceP closed 4 years ago
could you help me? :)
Okey share what you were trying
Hi @Benjacho , thank you for answering, what I am trying to do I described earlier.
Hello, congratulations on this useful package.
I am trying to manipulate the labels that the edit view shows. How can I do it?
I already managed to customize the list that shows my elements. but I can't customize the objects in the edit view.
@Benjacho If you need any specific clarification regarding my question, do not hesitate to tell me.
Any update about this? @Benjacho
I am also trying to achieve something similar. Basically, I have a computed property / Accessor on my related model and that is what I want to use to generate the options list.
@YarinceP Can you share how you were able to customize the output of the dropdown? I am trying to use a computed property on the model to do this (And using the optionsLabel method on the BelongsToManyField class) but it's not working.
Of course @techdaddies-kevin . I did it as follows:
add the following to the BelonsToManyField field in your nova resource
->options(\App\User::getMunicipios())
And then he performed a function in the model of his resource. Something like this:
public static function getMunicipios($columns=['*'])
{
return DB::table('municipios')
->join('estados', 'municipios.estado_id', '=', 'estados.id')
->select([
DB::raw("municipios.id"),
DB::raw("CONCAT(municipios.nombre,' - ',estados.nombre) AS nombre")])
->get(is_array($columns) ? $columns : func_get_args());
}
Thanks @YarinceP that helped me tremendously!
@Benjacho I'll try to explain the issue a better to make it more clear what the problem is.
First, I have a custom method on my Category
model. This method gets all of my categories, but then changes the name property of each of them to indicate their tiers.
I then reference this on the BelongsToManyField implementation
This works great for generating the dropdown, but the problem is that once you've saved the relationship and reload the form, the text input doesn't show the full item shown in the dropdown, it only shows the value from the name column
I tried to use the optionsLabel
method to get the value using a computed property on the model, but it didn't work.
Hey could you modify the title method of your reslationship resource to fit with your needs, to display field value names, we are using title method
Not really - If we change the Title attribute it's going to change that title everywhere. We only need this Category > Sub Category > Sub Sub Category organization for this dropdown. On the front-end of the site, we'd want the title to return just the title of that single category. The best solution for us is to allow the dropdown to use a custom attribute to generate the title for the selected items.
You can create a function getFullNameAttribute(){ return $this->name . $this->last_name} and append it to model $appends = ['full_name'] it is a mutator
@Benjacho Thank you. I had the custom attribute but I wasn't appending it, which is why it wasn't working.
So now here is my situation:
I have a resource that already has two categories assigned to it. I load the resource edit page, and the dropdown correctly shows the breadcrumbs like I'm wanting (For the two already-set relationships). However, the DROPDOWN does not show the breadcrumb representation like I want.
My opinion is that if the 'optionsLabel()' method is being called, that should also set the display value in the dropdown itself.
Is there some other way to set the dropdown options that I'm missing? I don't want to update the title
property of the resource because I only need to show this full representation in specific scenarios.
did you use options method?
@Benjacho Thank you. Appending the mutator fixed my issue.
Hello, congratulations on this useful package.
I am trying to manipulate the labels that the edit view shows. How can I do it?
I already managed to customize the list that shows my elements. but I can't customize the objects in the edit view.