Closed timcv closed 5 years ago
Yes it is possible you can make a PR or propose!
I sorry i made a misstake.
What i would want to to is be able to skip the ->options() call all together.
It should be possible to call ::all() on the class i enter as an argument to the ::make() method.
//Tim
I gave it a try but could not come up with with a solution...
I have an idea and that would be to ajax load the options on the details page, but i could not figure out how to get it working...
//Tim
Hello timcv i'll do my best to get this working!
Hi, i have worked a bit on another field for a private field.
A good solution would be to skip the options method and user the arguments from the ::make method to create an ajax request and fetch the data that way :)
I got the ide by reading the source code of https://github.com/dillingham/nova-attach-many .
//Tim
Yes that's a good idea, basically this options method is different because it allows you to subquery! But function options can override the default Ajax load
Thats sounds even better!
Hello @Benjacho - Thanks for a great package!
I'm having trouble setting the options using the options method. I want to set them to avoid the ajax loading time when there are lots of options.
BelongsToManyField::make('Towns')->options(function () {
return Town::select('id', 'name')
->get()
->map(function ($item, $key) {
return [
'id' => $item->id,
'name' => $item->name,
'value' => $item->id,
];
})->values();
}),
But I get no options in the dropdown. Can you explain to me how to use this method properly? Thanks.
I just figured out the problem was the anonymous function. Also I was over complicating the code. This seems to work nicely...
BelongsToManyField::make('Towns')
->options(
DB::table('silverware_towns')
->select('id', 'name')
->get()
->values()
),
Thanks again for a great package
Hello,
Would it be possible to add the possibility for the ->options method to take a closure as argument?
When doing like this ->options(\App\Role::all()) the field generates one query per row.
Do you think it would be possible to cache it by using a closure?
//Tim