GithubHelp home page GithubHelp logo

Comments (6)

DissNik avatar DissNik commented on June 6, 2024 2

Попробуйте переименовать связь attributes например на categoryAttributes

from moonshine.

AJIUK avatar AJIUK commented on June 6, 2024 1
<select class="form-select" x-data="select('')" data-search-enabled="data-search-enabled" data-remove-item-button="data-remove-item-button" value="[1]" id="attributes" name="attributes[]" multiple="multiple" x-on:change="onChangeField($event)">

image

<form class="form" method="POST" x-data="formBuilder(`crud`, [])" x-init="init({&quot;whenFields&quot;:[],&quot;reactiveUrl&quot;:&quot;&quot;})" action="http://127.0.0.1/admin/resource/category-resource/crud/1" enctype="multipart/form-data" x-id="['form']" :id="$id('form')">

image

from moonshine.

lee-to avatar lee-to commented on June 6, 2024

Спасибо за issue! Я проверил у себя и не обнаружил никаких ошибок, думаю дело в чем то еще, пришлите ресурс полностью

from moonshine.

AJIUK avatar AJIUK commented on June 6, 2024

CategoryResource:

<?php

declare(strict_types=1);

namespace App\MoonShine\Resources;

use Illuminate\Database\Eloquent\Model;
use App\Models\Category;

use MoonShine\Resources\ModelResource;
use MoonShine\Fields\ID;
use MoonShine\Fields\Relationships\BelongsTo;
use MoonShine\Fields\Relationships\BelongsToMany;
use MoonShine\Fields\Select;
use MoonShine\Fields\Slug;
use MoonShine\Fields\Text;

/**
 * @extends ModelResource<Category>
 */
class CategoryResource extends ModelResource
{
    protected string $model = Category::class;

    protected string $title = 'Категории';

    public string $column = 'name';

    public function indexFields(): array
    {
        return [
            ID::make()->sortable(),

            Select::make('Статус', 'status')
            ->options(Category::$statuses)
            ->default('new'),

            Text::make('Название', 'name'),
            Slug::make('Код', 'slug'),

            BelongsTo::make('Родитель', 'parent', resource: new CategoryResource())
            ->nullable(),
        ];
    }

    public function formFields(): array
    {
        return [
            ID::make()->sortable(),

            Select::make('Статус', 'status')
            ->options(Category::$statuses)
            ->default('new'),

            Text::make('Название', 'name'),
            Slug::make('Код', 'slug')->from('name'),

            BelongsTo::make('Родитель', 'parent', resource: new CategoryResource())
            ->nullable(),

            BelongsToMany::make('Атрибуты', 'attributes', resource: new AttributeResource())
            // ->asyncSearch()
            // ->selectMode(),
        ];
    }

    public function detailFields(): array
    {
        return [
            ID::make()->sortable(),

            Select::make('Статус', 'status')
            ->options(Category::$statuses)
            ->default('new'),

            Text::make('Название', 'name'),
            Slug::make('Код', 'slug'),

            BelongsTo::make('Родитель', 'parent', resource: new CategoryResource())
            ->nullable(),

            BelongsToMany::make('Атрибуты', 'attributes', resource: new AttributeResource()),
        ];
    }

    public function rules(Model $item): array
    {
        return [];
    }
}

AttributeResource:

<?php

declare(strict_types=1);

namespace App\MoonShine\Resources;

use Illuminate\Database\Eloquent\Model;
use App\Models\Attribute;

use MoonShine\Resources\ModelResource;
use MoonShine\Fields\ID;
use MoonShine\Fields\Select;
use MoonShine\Fields\Text;

/**
 * @extends ModelResource<Attribute>
 */
class AttributeResource extends ModelResource
{
    protected string $model = Attribute::class;

    protected string $title = 'Атрибуты';

    public string $column = 'name';

    public function indexFields(): array
    {
        return [
            ID::make()->sortable(),

            Text::make('Название', 'name'),
            Text::make('Код', 'code'),

            Select::make('Тип', 'type')
            ->options(Attribute::$types)
            ->default('text'),
        ];
    }

    public function formFields(): array
    {
        return [
            ID::make()->sortable(),

            Text::make('Название', 'name'),
            Text::make('Код', 'code'),

            Select::make('Тип', 'type')
            ->options(Attribute::$types)
            ->default('text'),
        ];
    }

    public function detailFields(): array
    {
        return [
            ID::make()->sortable(),

            Text::make('Название', 'name'),
            Text::make('Код', 'code'),

            Select::make('Тип', 'type')
            ->options(Attribute::$types)
            ->default('text'),
        ];
    }

    public function rules(Model $item): array
    {
        return [];
    }
}

from moonshine.

lee-to avatar lee-to commented on June 6, 2024

Покажите пожалуйста как выглядит html тег select, скопируйте именно код селекта а не врапперов и у основной формы будут дата атрибуты x-init вот его тоже покажите

from moonshine.

AJIUK avatar AJIUK commented on June 6, 2024

Это сработало

from moonshine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.