laravel-admin
laravel-admin copied to clipboard
Polymorphic relation form
Add polymorphic relation field support.
Usage example:
$form->radioButton('menuable_type', __('Link to'))->options([
(new PageCategory())->getMorphClass() => __('Page Category'),
(new Page())->getMorphClass() => __('Page'),
(new Category())->getMorphClass() => __('Product Category'),
(new Product())->getMorphClass() => __('Product'),
])->when((new PageCategory())->getMorphClass(), function (Form $form) {
$form->morphTo('menuable', PageCategories::class, "Menu Object");
})->when((new Page())->getMorphClass(), function (Form $form) {
$form->morphTo('menuable', Pages::class, "Menu Object");
})->when((new Category())->getMorphClass(), function (Form $form) {
$form->morphTo('menuable', Categories::class, "Menu Object");
})->when((new Product())->getMorphClass(), function (Form $form) {
$form->morphTo('menuable', Products::class, "Menu Object");
});