Skip to content

Commit 86d2d74

Browse files
committed
part second and excel file updated
1 parent edbd311 commit 86d2d74

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

EasyShop/app/Http/Controllers/AdminController.php

+21
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,27 @@ public function import_products(Request $request){
259259
'file' => 'required|mimes:csv,txt'
260260
]);
261261

262+
if(($handle = fopen($_FILES['file']['tmp_name'],"r")) !== FALSE){
263+
fgetcsv($handle); // remove first row of excel file such as product name,price,code
264+
265+
while(($data = fgetcsv($handle,1000,",")) !==FALSE){
266+
267+
$addPro = DB::table('products')->insert([
268+
'pro_name' => $data[0],
269+
'pro_code' => $data[1],
270+
'pro_info' => $data[2],
271+
'pro_img' => $data[3],
272+
'pro_price' => $data[4],
273+
'cat_id' => $data[5],
274+
'stock' => '10',
275+
'new_arrival' => '0',
276+
'spl_price' => '0',
277+
'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
278+
'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
279+
]);
280+
}
281+
}
282+
262283
}
263284

264285

productsdata.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
product_name,pro code,pro info,pro img,pro price,cat id
2+
dummy pro 1,dfdf34,this is dummy pro 1,http://lorempixel.com/300/400/cats/?83121,200,1
3+
dummy pro 2,fvf4r45,this is dummy pro 2,http://lorempixel.com/300/400/cats/?83126,245,2

0 commit comments

Comments
 (0)