Skip to content
Advertisement

insert data from session array in laravel 6

i want to insert a record of form fields in table and also values from session array

i have a form with following fields

JavaScript

and i have session array 'cartS' like this

JavaScript

so i have a table in which following fields

JavaScript

here i have model called order model

i have one controller in which there is public function placeorder(Request $request)

i can get value from form-fields using $request

but what about pid and qnty which are in session array(associative array)

if i do foreach loop then it only gives value of one key but i have 2 keys in session array

JavaScript

if i return $pid then it gives only first key’s pid but not all

following is my placeorder function

JavaScript

i don’t know if i am right or wrong by writing above function but i want to insert record like following

if it is not good approach then kindly suggest one : )

JavaScript

here i am trying to insert value of pid and qnty are using implode/explode

honestly i’ve never tried implode/explode

or

JavaScript

please give your suggestions-answers whatever etc : )

Advertisement

Answer

If there are 2 products in your cart, (i think) you must have 2 records in order table, also you need to add one more column to group orders, for example order_tag which will contain unique string Second way is to divide orders table in two tables

JavaScript

Then you can easily find(query) orders detail. Saving products will look like that

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement