ProductsController::form 方法和 CategoriesController::form 方法中的类目 select 实现不同?

  1. CategoriesController::form
    $form->select('parent_id', '父类目')->ajax('/admin/api/categories');
  2. ProductsController::form
    $form->select('category_id', '类目')
            ->options(function ($id) {
                $category = Category::find($id);
                if ($category) {
                    return [$category->id => $category->full_name];
                }
            })->ajax('/admin/api/categories?is_directory=0');

    主要疑问是options那里,我尝试把 ProductsController::form中的options去掉,也能正常新增、编辑商品啊,这里加options的意义是什么?

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
leo
最佳答案

如果 ProductsController 不加 options,在编辑时会『类目』会变成空。

而编辑类目时不允许修改父类目,Laravel-Admin 就会自动把对应的类目名称读取出来,所以不需要加 options

5年前 评论
讨论数量: 2
leo

如果 ProductsController 不加 options,在编辑时会『类目』会变成空。

而编辑类目时不允许修改父类目,Laravel-Admin 就会自动把对应的类目名称读取出来,所以不需要加 options

5年前 评论

@leo 噢,是编辑时商品的类目没显示出来,手动选择还是可以保存的,感谢大佬解惑

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!