crud->addColumns([ [ 'name' => 'name', 'type' => 'text', 'label' => 'Name' ], [ 'name' => 'max_size', 'type' => 'number', 'label' => 'Max size (KBytes)', 'default' => 0 ], [ 'name' => 'business', 'type' => 'radio', 'label' => 'Enterpreneurs', 'options' => [ 1 => 'Yes', 0 => 'No' ] ], [ 'name' => 'company', 'type' => 'radio', 'label' => 'Companies', 'options' => [ 1 => 'Yes', 0 => 'No' ] ], [ 'name' => 'all_country', 'type' => 'radio', 'label' => 'All countries', 'options' => [ 1 => 'Yes', 0 => 'No' ] ], [ 'label' => "Document Countries", 'type' => 'select_multiple', 'name' => 'countries', 'entity' => 'countries', 'model' => "App\Models\Country", 'attribute' => 'name', 'pivot' => true, 'options' => (function ($query) { return $query->orderBy('name', 'ASC')->get(); }), ], ]); } /** * Define what happens when the Create operation is loaded. * * @see https://backpackforlaravel.com/docs/crud-operation-create * @return void */ protected function setupCreateOperation() { CRUD::setValidation(DocumentRequest::class); $this->crud->addFields([ [ 'name' => 'name', 'type' => 'text', 'label' => 'Name' ], [ 'name' => 'description', 'type' => 'textarea', 'label' => 'Description' ], [ 'name' => 'max_size', 'type' => 'number', 'label' => 'Max size (KBytes)', 'default' => 0 ], [ // Checkbox 'name' => 'business', 'label' => 'Enterpreneurs', 'type' => 'checkbox' ], [ // Checkbox 'name' => 'company', 'label' => 'Companies', 'type' => 'checkbox' ], [ // Checkbox 'name' => 'all_country', 'label' => 'All countries', 'type' => 'checkbox' ], // [ // SelectMultiple = n-n relationship (with pivot table) // 'label' => "Document Groups", // 'type' => 'select_multiple', // 'name' => 'groups', // the method that defines the relationship in your Model // // optional // 'entity' => 'groups', // the method that defines the relationship in your Model // 'model' => "App\Models\Documentgroup", // foreign key model // 'attribute' => 'name', // foreign key attribute that is shown to user // 'pivot' => true, // on create&update, do you need to add/delete pivot table entries? // // also optional // 'options' => (function ($query) { // return $query->orderBy('name', 'ASC')->get(); // }), // force the related options to be a custom query, instead of all(); you can use this to filter the results show in the select // ], [ 'label' => "Document Countries", 'type' => 'select2_multiple', 'name' => 'countries', 'entity' => 'countries', 'model' => "App\Models\Country", 'attribute' => 'name', 'pivot' => true, 'options' => (function ($query) { return $query->orderBy('name', 'ASC')->get(); }), ], [ 'name' => 'max_size', 'type' => 'text', 'label' => 'Max size (KBytes)' ] ]); } /** * Define what happens when the Update operation is loaded. * * @see https://backpackforlaravel.com/docs/crud-operation-update * @return void */ protected function setupUpdateOperation() { $this->setupCreateOperation(); } }