定制 tokarskimarcin/laravel-admin-ext-select-inline-create 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tokarskimarcin/laravel-admin-ext-select-inline-create

Composer 安装命令:

composer require tokarskimarcin/laravel-admin-ext-select-inline-create

包简介

Inline creating entity while in another form.

README 文档

README

preview Use select field to create entity if not exists. Created entity is selected immediately.

Requires

  • "php": ">=7.2.0",
  • "encore/laravel-admin": "~1.6"
  • "tokarskimarcin/laravel-admin-ext-modal-form": "^0.1"

Installation

Publishing

Execute command below to publish package. It will copy vendor resources to your application public directory.

php artisan admin:select-inline-create:publish

Update

To update/overwrite assets of package add --force option to publishing command.

Documentation

Usage

SelectInlineCreate field can be used by executing method selectInlineCreate on Admin/Form.

use Encore\Admin\Auth\Database\Administrator;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;

Admin::form(new Administrator(), function (Form $form){
    $form->selectInlineCreate('manager', 'Manager');
    ...;
});

While entity is created it looks for the option by searching url with id parameter in query string. Use SelectResponse class and static function get to return proper response.

use Encore\SelectInlineCreate\Form\SelectResponse;
use Illuminate\Support\Facades\Request;

class SearchController{
    public function search(){
        $id = Request::offsetGet('id');

        // SelectResponse::get($entity, $callback)
        // $entity can be null, then SelectResponse will return suitable message
        // in $callback return array with 'id' and 'text' keys. 
        // js will create an option based on this

        return SelectResponse::get(
            Administrator::query()->find($id),
            function(Administrator $administrator){
                return ['id' => $administrator->id, 'text' => $administrator->name];
            });
    }
}

Methods

SelectInlineCreate has same methods as regular Select from Admin

1. setSearchUrl

If ajax(...) function it's not used so setSearchUrl should be used.

//Example
$form->selectInlineCrate(...)
    ->setSearchUrl(route('manager.search'))
    ->options(...);

If ajax(...) is used then setSearchUrl is executed inside of ajax and searching url is the same as ajax.

$form->selectInlineCrate(...)
    ->ajax(route('manager.search'));

Search url can be overwritten if it's set by ajax function. To do that setSearchUrl must be executed after ajax.

$form->selectInlineCrate(...)
    ->ajax(route('manager.search-by-query'))
    ->setSearchUrl(route('manager.search-by-id'));

统计信息

  • 总下载量: 30
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固