laravel-admin icon indicating copy to clipboard operation
laravel-admin copied to clipboard

Polymorphic relation form

Open NikolayMurha opened this issue 1 year ago • 0 comments

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");
});

NikolayMurha avatar Aug 30 '22 15:08 NikolayMurha