mercredi 24 août 2016

Fetching records using id in array and storing in table in eloquent

I have a database table called 'collection' which holds the following fields: id record_id collector_id month year package total_bill created_at updated_at

The package price for individual record is stored in another table called 'records'. When an admin enters info using a form, record_id,which is a foreign key,is taken as an array

public function store(Request $request)
    {
        $inputs=$request->all();
        $customers=$inputs['record_id'];
        var_dump($customers);

        $record=new Record();




        $data = []; 
        foreach ($customers as $customer ) {
          // $user = DB::table('records')->where('id','=', $customer)->get();


            $data[] = [
                'collector_id' => $inputs['collector_id'],
                'month'        => $inputs['month'],
                'record_id'    => $customer,              
                'year'         => $inputs['year'],
                'created_at'   => Carbon::now(),
                'updated_at'   => Carbon::now(),



            ];
        }



      $record->collections()->insert($data);



       return redirect()->intended('/home/collection')->with([
         'success' => 'THANKS.INFORMATION HAS BEEN RECORDED!'

         ]);

      }

Using this function in controller,I am storing the values. But how can I retrieve the package price from records table using record_id and store in the 'collections' table.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire