mysql - Store multiple rows data with multiple columns using table field in backpack for laravel -


i creating form has product , multiple prices @ multiple stores i.e. amazon, ebay, etc. compare price , provide minimum price consumer.

i have problem build type of form. unable store data in database using table field of backpack, need it.

crud controller:

<?php namespace app\http\controllers\admin; use backpack\crud\app\http\controllers\crudcontroller; // validation: change requests match own file names if need form validation use app\http\requests\menrequest storerequest; use app\http\requests\menrequest updaterequest; class mencrudcontroller extends crudcontroller {     public function setup()     {         $this->crud->setmodel('app\models\men');         $this->crud->setroute(config('backpack.base.route_prefix') . '/men');         $this->crud->setentitynamestrings('men', 'mens');         //$this->crud->setfromdb();         // ------ crud fields         // $this->crud->addfield($options, 'update/create/both');         // $this->crud->addfields($array_of_arrays, 'update/create/both');         $this->crud->addfields([             [ // table               'name' => 'mens',               'label' => 'options',               'type' => 'table',               'entity_singular' => 'option', // used on "add x" button               'columns' => [                   'name' => 'name',                   'price'=>'price',               ],               'max' => 5, // maximum rows allowed in table                'min' => 0 // minimum rows allowed in table             ],         ]);         // $this->crud->removefield('name', 'update/create/both');         // $this->crud->removefields($array_of_names, 'update/create/both');         // ------ crud columns         // $this->crud->addcolumn(); // add single column, @ end of stack         // $this->crud->addcolumns(); // add multiple columns, @ end of stack         $this->crud->addcolumns(             [                 [                     'label'  =>'product name',                     'name'   =>'name',                 ],             ]);         // $this->crud->removecolumn('column_name'); // remove column stack         // $this->crud->removecolumns(['column_name_1', 'column_name_2']); // remove array of columns stack         // $this->crud->setcolumndetails('column_name', ['attribute' => 'value']); // adjusts properties of passed in column (by name)         // $this->crud->setcolumnsdetails(['column_1', 'column_2'], ['attribute' => 'value']);         // ------ crud buttons         // possible positions: 'beginning' , 'end'; defaults 'beginning' 'line' stack, 'end' others;         // $this->crud->addbutton($stack, $name, $type, $content, $position); // add button; possible types are: view, model_function         // $this->crud->addbuttonfrommodelfunction($stack, $name, $model_function_name, $position); // add button html returned method in crud model         // $this->crud->addbuttonfromview($stack, $name, $view, $position); // add button html in view placed @ resources\views\vendor\backpack\crud\buttons         // $this->crud->removebutton($name);         // $this->crud->removebuttonfromstack($name, $stack);         // $this->crud->removeallbuttons();         // $this->crud->removeallbuttonsfromstack('line');          // ------ crud access         // $this->crud->allowaccess(['list', 'create', 'update', 'reorder', 'delete']);         // $this->crud->denyaccess(['list', 'create', 'update', 'reorder', 'delete']);         // ------ crud reorder         // $this->crud->enablereorder('label_name', max_tree_level);         // note: need allow access right users: $this->crud->allowaccess('reorder');          // ------ crud details row         // $this->crud->enabledetailsrow();         // note: need allow access right users: $this->crud->allowaccess('details_row');         // note: need overwrite showdetailsrow($id) method in entitycrudcontroller show whatever you'd in details row or overwrite views/backpack/crud/details_row.blade.php         // ------ revisions         // need use \venturecraft\revisionable\revisionabletrait;         // please check out: https://laravel-backpack.readme.io/docs/crud#revisions         // $this->crud->allowaccess('revisions');         // ------ ajax table view         // please note drawbacks of though:         // - 1-n , n-n columns not searchable         // - date , datetime columns won't sortable anymore         // $this->crud->enableajaxtable();         // ------ datatable export buttons         // show export pdf, csv, xls , print buttons on table view.         // not work ajax datatables.         // $this->crud->enableexportbuttons();         // ------ advanced queries         // $this->crud->addclause('active');         // $this->crud->addclause('type', 'car');         // $this->crud->addclause('where', 'name', '==', 'car');         // $this->crud->addclause('wherename', 'car');         // $this->crud->addclause('wherehas', 'posts', function($query) {         //     $query->activeposts();         // });         // $this->crud->addclause('withoutglobalscopes');         // $this->crud->addclause('withoutglobalscope', visiblescope::class);         // $this->crud->with(); // eager load relationships         // $this->crud->orderby();         // $this->crud->groupby();         // $this->crud->limit();     }     public function store(storerequest $request)     {         // additional operations before save here         $redirect_location = parent::storecrud();         // additional operations after save here         // use $this->data['entry'] or $this->crud->entry         return $redirect_location;     }     public function update(updaterequest $request)     {         // additional operations before save here         $redirect_location = parent::updatecrud();         // additional operations after save here         // use $this->data['entry'] or $this->crud->entry         return $redirect_location;     } } 

model

<?php namespace app\models; use illuminate\database\eloquent\model; use backpack\crud\crudtrait; class men extends model {     use crudtrait;       protected $table = 'mens';       protected $primarykey = 'id';        public $timestamps = false;        //protected $guarded = ['id'];        protected $fillable = ['category','name','price','shipping','mrp','product_id'];     // protected $hidden = [];     // protected $dates = [];        protected function castattribute($key, $value)   {     switch ($this->getcasttype($key))     {       case 'int':       case 'integer':         return (int) $value;       case 'real':       case 'float':       case 'double':         return (float) $value;       case 'string':         return (string) $value;       case 'bool':       case 'boolean':         return (bool) $value;       case 'object':         return json_decode($value);       case 'array':       case 'json':         return json_decode($value, true);       default:         return $value;     }   } 

}


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -