Laravel背包Inlinecreate操作方法不允许错误

发布于 2025-02-06 17:36:44 字数 1570 浏览 2 评论 0原文

尝试使用inline_create我可以在模态中创建,但我无法选择我得到错误

方法不允许使用此路线的邮政方法。 支持的方法:获取,头。

url is:

Field

$this->crud->addField(
            [
                'label' => "Les mote clé",
                'minimum_input_length' => 0,
                'type'      => 'relationship',
                'name'      => 'tags', // the method that defines the relationship in your Model
                'ajax' => true,
                // 'method'                  => 'GET',
                'minimum_input_length' => 0,
                'attribute' => 'name', // foreign key attribute that is shown to user
                'inline_create' =>  [ // specify the entity in singular
                    'entity' => 'tag', // the entity in singular
                    'force_select' => true, // should the inline-created entry be immediately selected?
                    'modal_class' => 'modal-dialog modal-md', // use modal-sm, modal-lg to change width
                    'modal_route' => route('tag-inline-create'), // InlineCreate::getInlineCreateModal()
                    'create_route' =>  route('tag-inline-create-save'), // InlineCreate::storeInlineCreate()
                ]  
            ]
        );

Question modal 

// tags 
public function tags()
{
    return $this->belongsToMany(Tag::class, 'question_tags', 'question_id', 'tag_id');
}

Trying to use inline_create i can create in modal but i can't select i get error

Method not allowed The POST method is not supported for this route.
Supported methods: GET, HEAD.

URL is : http://127.0.0.1:8000/admin/question/fetch/tags

Field

$this->crud->addField(
            [
                'label' => "Les mote clé",
                'minimum_input_length' => 0,
                'type'      => 'relationship',
                'name'      => 'tags', // the method that defines the relationship in your Model
                'ajax' => true,
                // 'method'                  => 'GET',
                'minimum_input_length' => 0,
                'attribute' => 'name', // foreign key attribute that is shown to user
                'inline_create' =>  [ // specify the entity in singular
                    'entity' => 'tag', // the entity in singular
                    'force_select' => true, // should the inline-created entry be immediately selected?
                    'modal_class' => 'modal-dialog modal-md', // use modal-sm, modal-lg to change width
                    'modal_route' => route('tag-inline-create'), // InlineCreate::getInlineCreateModal()
                    'create_route' =>  route('tag-inline-create-save'), // InlineCreate::storeInlineCreate()
                ]  
            ]
        );

Question modal 

// tags 
public function tags()
{
    return $this->belongsToMany(Tag::class, 'question_tags', 'question_id', 'tag_id');
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

决绝 2025-02-13 17:36:44

我终于找到了这个问题。
我需要定义与该领域合作的Ajax路线,要么创建自己的端poin,要么使用fetchoperation https://backpackforlaravel.com/docs/5.x/crud-operation-fetch#about-1

QuestionCrudController中:

    use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
...

    public function fetchTags()
    {
       return $this->fetch(Tag::class);
    }

I finally found the problem.
I needed to define the ajax route to work with the field, either creating my own endpoin, or using FetchOperation https://backpackforlaravel.com/docs/5.x/crud-operation-fetch#about-1.

In QuestionCrudController:

    use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
...

    public function fetchTags()
    {
       return $this->fetch(Tag::class);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文