Comments (2)
Probably answer you might not need anymore, and which should definitely be documented.
You are correct to assume that filtering can be done through api()
method. The way to do it is to add it to Multiselect
element and publish the route like this:
// In resource
Multiselect::make('Products')
->api('/api/multiselect/products', Product::class)
->singleSelect(), // <-- I am using single select for this, you don't need to.
// In api.php
Route::get('multiselect/products', MultiselectProductController::class);
And then this is what the controller should look like:
public function __invoke(Request $request): JsonResponse
{
$search = $request->get('search'); // <--- you will get user input through this
if (!$search) {
return response()->json(); // <--- if you want empty result, you need to return empty json
}
$products = Product::query()
->where('allowed_for_purchase', true)
->where('title', 'LIKE', "%{$search}%")
->get();
if ($products->isEmpty()) {
return response()->json();
}
return response()->json($products->pluck('title', 'id')); // <--- pluck the results for showing them in the frontend correctly
}
Some notes:
- If you return
response()->json([])
, you will get empty row back instead of "No results found" - Plucking needs to have
id
set as key so you can pick it up later - I found no value in
api()
third parameter ($keyName
), as it didn't change a thing
Hope it helps
from nova-multiselect-field.
I'll leave it with tutorial label at the moment.
If anybody has time and interest, we are open to pull requests with a summary to update the docs.
from nova-multiselect-field.
Related Issues (20)
- bug with `hide()` method
- Change the visibility of the resolveDefaultValue method to public HOT 1
- Getting this error after installing outline nova-menu-builder HOT 1
- Create issue with belongsToMany if no option selected HOT 2
- Bug: Unhide field on DependsOn doesn't send value HOT 2
- Data display with optionsDependOn
- ->dependsOn() is returning string not array of values from Multiselect (Nova 4.22.1+)
- Feature request: Show resource avatar
- Handling a Relatable BelongsToMany HOT 1
- DependsOn with api() HOT 1
- Values passed to Overwritten detail field don't come from displayUsing or resolveUsing HOT 1
- BelongsToMany Only Shows IDs / How to specify mapping HOT 1
- MorphedByMany support
- Migrate from `vue-multiselect` to `vueform/multiselect` HOT 1
- Clear Validate
- Please add 'Option groups' support with dependsOnOptions
- Is not compatible with Nova v4.32.14 HOT 1
- Adding a HasMany relation correctly HOT 2
- Use taggable dynamic content in other field dependsOn dynamically
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 nova-multiselect-field.