From 11c034bae979250aed3609216f213ef06eb3f987 Mon Sep 17 00:00:00 2001 From: Luis Date: Thu, 16 Aug 2018 17:16:03 +0000 Subject: [PATCH] updated docs --- docs/en/model-form-fields.md | 16 ++++++++++++++++ docs/zh/model-form-fields.md | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/docs/en/model-form-fields.md b/docs/en/model-form-fields.md index d1eb7c9288..d8d520993b 100644 --- a/docs/en/model-form-fields.md +++ b/docs/en/model-form-fields.md @@ -84,6 +84,14 @@ $form->select('user_id')->options(function ($id) { return [$user->id => $user->name]; } })->ajax('/admin/api/users'); + +// using ajax and show selected item: + +$form->select('user_id')->options(User::class)->ajax('/admin/api/users'); + +// or specifying the name and id + +$form->select('user_id')->options(User::class, 'name', 'id')->ajax('/admin/api/users'); ``` Notice:if you have modified the value of the `route.prefix` in the `config/admin.php` file, this api route should be modified to `config('admin.route.prefix').'/api/users'`. @@ -171,6 +179,14 @@ public function city(Request $request) ## Multiple select ```php $form->multipleSelect($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name']); + +// using ajax and show selected items: + +$form->multipleSelect($column[, $label])->options(Model::class)->ajax('ajax_url'); + +// or specifying the name and id + +$form->multipleSelect($column[, $label])->options(Model::class, 'name', 'id')->ajax('ajax_url'); ``` You can store value of multiple select in two ways, one is `many-to-many` relation. diff --git a/docs/zh/model-form-fields.md b/docs/zh/model-form-fields.md index 99c5ccc6bd..0b8602ceea 100644 --- a/docs/zh/model-form-fields.md +++ b/docs/zh/model-form-fields.md @@ -77,6 +77,14 @@ $form->select($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Opt 或者从api中获取选项列表: ```php $form->select($column[, $label])->options('/api/users'); + +// 使用ajax并显示所选项目 + +$form->select($column[, $label])->options(Model::class)->ajax('/api/users'); + +// 或指定名称和ID + +$form->select($column[, $label])->options(Model::class, 'name', 'id')->ajax('/api/users'); ``` 其中api接口的格式必须为下面格式: ```php @@ -190,6 +198,14 @@ public function city(Request $request) ```php $form->multipleSelect($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name']); + +// 使用ajax并显示所选项目: + +$form->multipleSelect($column[, $label])->options(Model::class)->ajax('ajax_url'); + +// 或指定名称和ID + +$form->multipleSelect($column[, $label])->options(Model::class, 'name', 'id')->ajax('ajax_url'); ``` 多选框可以处理两种情况,第一种是`ManyToMany`的关系。