Tuesday, April 11, 2017

insert data into 2 different table from single controller form in laravel

i have two table called visit and prescription. i want to insert, 2 data to the prescription table and 1 data to the visit table, column called status and present data in status, i have default data called 'pending' in visit table. below is my code i used.

$this->table = "prescription";

        $this->col = [];
        $this->col[] = ["label"=>"Patient ID","name"=>"cid","join"=>"visit,patient_Id"];
        $this->col[] = ["label"=>"Prescriptions","name"=>"prescriptions"];
        $this->col[] = ["label"=>"Doctor","name"=>"cms_users_id","join"=>"cms_users,name"];

        $this->form = [];
        $this->form[] = ['label'=>'Patient ID','name'=>'cid','type'=>'datamodal','validation'=>'required','width'=>'col-sm-7','datamodal_table'=>'visit','datamodal_columns'=>'patient_Id,level,doctor','datamodal_size'=>'small'];
        $this->form[] = ['label'=>'Prescriptions','name'=>'prescriptions','type'=>'wysiwyg','validation'=>'required|min:1|max:255','width'=>'col-sm-10'];

        * above data should insert in prescription table but below one data should insert or update in visit table.

        $this->form[] = ['label'=>'Treatment status','name'=>'status','type'=>'radio','width'=>'col-sm-7','dataenum'=>'Treated','table'=>'visit'];

with this code i can insert only in to prescription table.

so please help me to get this answer.



via kinzang

Advertisement