crud->setModel('App\Models\Material'); $this->crud->setRoute(config('backpack.base.route_prefix') . '/material'); $this->crud->setEntityNameStrings('material', 'materials'); $this->crud->orderBy('updated_at', 'DESC'); /* |-------------------------------------------------------------------------- | CrudPanel Configuration |-------------------------------------------------------------------------- */ // TODO: remove setFromDb() and manually define Fields and Columns //$this->crud->setFromDb(); $this->crud->addColumns([ ['name' => 'title','type' => 'text', 'label' => trans('admin.title')], [ // n-n relationship (with pivot table) 'label' => "Categories", // Table column heading 'type' => "select_multiple", 'name' => 'categories', // the method that defines the relationship in your Model 'entity' => 'categories', // the method that defines the relationship in your Model 'attribute' => "name", // foreign key attribute that is shown to user 'model' => "App\Models\Category", // foreign key model ], ['name' => 'view','type' => 'text', 'label' => trans('admin.view')], ['name' => 'total_likes','type' => 'text', 'label' => trans('admin.like')], ['name' => 'price','type' => 'text', 'label' => trans('admin.price')], ['name' => 'size','type' => 'text', 'label' => trans('admin.size')], ['name' => 'duration','type' => 'text', 'label' => trans('admin.duration')], ['name' => 'day_count','type' => 'text', 'label' => trans('admin.day_count')], ['name' => 'download_count','type' => 'text', 'label' => trans('admin.download_count')], ]); $this->crud->addFields([ ['name' => 'title','type' => 'text', 'label' => trans('admin.title'),'tab' => trans('admin.material.firsttab')], [ 'name' => 'categories', 'type' => 'select2_multiple', 'entity' => 'categories', 'attribute' =>'name', 'model' => 'App\Models\Category', 'pivot' => true, 'lable'=>trans('admin.category'), 'tab' => trans('admin.material.firsttab') ], ['name' => 'desc','type' => 'textarea', 'label' => trans('admin.desc'),'tab' => trans('admin.material.firsttab')], ['suffix' => 'man.','attributes' => ["step" => "any"],'name' => 'price','type' => 'number', 'label' => trans('admin.price'),'tab' => trans('admin.material.secondtab')], ['suffix'=>'Mb','attributes' => ["step" => "any"],'name' => 'size','type' => 'number', 'label' => trans('admin.size'),'tab' => trans('admin.material.secondtab')], ['suffix'=>'min.','attributes' => ["step" => "any"],'name' => 'duration','type' => 'number', 'label' => trans('admin.duration'),'tab' => trans('admin.material.secondtab')], [ // image 'tab' => trans('admin.material.thirdtab'), 'label' => trans('admin.material_image'), 'name' => "banner_url", 'type' => 'browse'], ['name' => 'trailer_url','type' => 'browse', 'label' => trans('admin.trailer_url'),'tab' => trans('admin.material.thirdtab')], ['name' => 'content_url','type' => 'browse', 'label' => trans('admin.content_url'),'tab' => trans('admin.material.thirdtab')], ['name' => 'day_count','type' => 'number', 'label' => trans('admin.day_count'),'tab' => trans('admin.material.secondtab')], ['name' => 'download_count','type' => 'number', 'label' => trans('admin.download_count'),'tab' => trans('admin.material.secondtab')], [ // Table 'name' => 'details', 'label' => trans('admin.material.extras'), 'type' => 'table', 'entity_singular' => 'detail', // used on the "Add X" button 'columns' => [ 'name' => 'Name', 'desc' => 'Description' ], 'tab' => trans('admin.material.fourthtab'), ], ]); // add asterisk for fields that are required in MaterialRequest $this->crud->setRequiredFields(StoreRequest::class, 'create'); $this->crud->setRequiredFields(UpdateRequest::class, 'edit'); } public function store(StoreRequest $request) { // your additional operations before save here $redirect_location = parent::storeCrud($request); // your additional operations after save here // use $this->data['entry'] or $this->crud->entry return $redirect_location; } public function update(UpdateRequest $request) { // your additional operations before save here $redirect_location = parent::updateCrud($request); // your additional operations after save here // use $this->data['entry'] or $this->crud->entry return $redirect_location; } }