Как установить рекордную сводную таблицу на рюкзак - PullRequest
0 голосов
/ 02 июля 2019

Я хочу вставить запись в мою сводную таблицу, в которой есть company_id и chef_id использование рюкзака может помочь, как я могу это сделать ниже - код моего контроллера crud

|-------------------------------------------------------------------------- | CrudPanel Basic Information введите код здесь` | ------------------------------------------------- -------------------------

    $this->crud->setModel('App\Models\Chef');
    $this->crud->setRoute(config('backpack.base.route_prefix') . '/chef');
    $this->crud->setEntityNameStrings('chef', 'chef');

    |--------------------------------------------------------------------------
    | CrudPanel Configuration
    |--------------------------------------------------------------------------
    */

    // TODO: remove setFromDb() and manually define Fields and Columns
    // $this->crud->setFromDb();
    $this->crud->addColumns([
        [
            'label' => __("Company Name"),
            'name' => 'company_id',
            'type' => 'select',
            'entity' => 'companies',
            'attribute' => 'name',                
        ],
        [
            'label' => __("Chef Name"),
            'name' => 'chef_id',
            'type' => 'select',
            'entity' => 'users',
            'attribute' => 'name'
        ]
    ]);

    // $managers = Manager::all()->pluck('manager_id')->toArray();
    // $users = User::whereIs('manager')->whereNotIn('id',$managers)->pluck('name','id')->toArray();        
    $users = User::whereIs('chef')->pluck('name','id')->toArray();        
    $this->crud->addFields([
        [
            'label' => __("Company Name"),
            'name' => 'companies',
            'type' => 'select2_multiple',
            'entity' => 'companies',
            'attribute' => 'name',
            'model' => 'App\Models\Company',
            'pivot' => true,
            'select_all' => true,
            'foreign_pivot_key' => 'company_id'
        ],
        [
            'label' => __("Chef Name"),
            'name' => 'chef_id',
            'type' => 'select2_from_array',
            'options' => $users               
        ]
    ]);


    // add asterisk for fields that are required in ManagerRequest
    $this->crud->setRequiredFields(StoreRequest::class, 'create');
    $this->crud->setRequiredFields(UpdateRequest::class, 'edit');
}`
...