alvinhu / nova-child-select Goto Github PK
View Code? Open in Web Editor NEWChild select field for Laravel Nova
Child select field for Laravel Nova
CREATE TABLE category
(
id
INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
title
VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
parent_category_id
INT(10) UNSIGNED NULL DEFAULT NULL,
enabled
TINYINT(1) NOT NULL DEFAULT '1',
title_en
VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
PRIMARY KEY (id
) USING BTREE,
INDEX category_parent_category_id_foreign
(parent_category_id
) USING BTREE,
CONSTRAINT category_parent_category_id_foreign
FOREIGN KEY (parent_category_id
) REFERENCES inar_local_refactored
.category
(id
) ON UPDATE RESTRICT ON DELETE RESTRICT
)
Select::make('Category')
->options(\App\Category::all()->mapWithKeys(function ($category) {
return [$category->id => $category->title];
}))
->rules('required'),
ChildSelect::make('Category')
->parent('id')
->options(function ($value) {
\App\Category::whereParentCategoryId($value)->get()->mapWithKeys(function ($category) {
return [$category->id => $category->title];
});
})
->rules('required'),
what I'm doing wrong? you example in lib doesn not show initial DB structure.
can not find the field in tabs "eminiarts/nova-tabs"
in options controller $field returns null
$field = $fields->findFieldByAttribute($attribute);
How to Use this package in BelongsToMany Relation, I am currently doing this
BelongsToMany::make('Periods') ->fields(function () { return [ ChildSelect::make('Start Date', 'from_date') ->options(function ($value) { Period::where('id', $value)->get()->mapWithKeys(function ($period) { return [$period->id => $period->from_date]; }); }), ]; }),
But This does not work
If` I return this as select options from the resources
[`
'MS' => ['label' => 'Small', 'group' => 'Men Sizes'],
'MM' => ['label' => 'Medium', 'group' => 'Men Sizes'],
'WS' => ['label' => 'Small', 'group' => 'Women Sizes'],
'WM' => ['label' => 'Medium', 'group' => 'Women Sizes'],
]
group will be ignored and it is rendered as normal select without the option group.
I am having an issue using a different nova package other than Select
as the main parent. . Is there any way we can use another package? is this possible and what is the current functionality to watching the Standard Select Field?
public function fields()
{
return [
Select::make('Provider', 'provider')
->options((\App\Person::all())
->rules('required')
}
\App\Person::all() is causing N+1 Query, How do I prevent it ?
It should be
ChildSelect::make('City')
->parent('country')
->options(function ($value) {
return City::whereCountry($value)->get()->mapWithKeys(function ($city) {
return [$city->id => $city->name];
});
})
->rules('required'),
Hi,
Excellent package, but is there any way to prevent this? For every row on the index these queries are run, thus having a negative impact on performance (haven't measured though).
Select::make('Country')
->options(\App\Models\Country::all()->mapWithKeys(function ($country) {
return [$country->id => $country->name];
}))
->onlyOnForms()
->rules('required', 'integer'),
ChildSelect::make('City')
->parent('country')
->options(function ($value) {
\App\Models\City::whereCountryId($value)->get()->mapWithKeys(function ($city) {
return [$city->id => $city->name];
});
})
->onlyOnForms()
->rules('required', 'integer'),
Select::make('Country')
->options(\App\Models\Country::all()->mapWithKeys(function ($country) {
return [$country->id => $country->name];
}))
->onlyOnForms()
->rules('required', 'integer'),
ChildSelect::make('City')
->parent('country')
->options(function ($value) {
\App\Models\City::whereCountryId($value)->get()->mapWithKeys(function ($city) {
return [$city->id => $city->name];
});
})
->onlyOnForms()
->rules('required', 'integer'),
nova version: 2.0.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.