diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index b736b3f..34f8dfe 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -35,7 +35,7 @@ class ItemController extends Controller ->leftJoin('files','items.iid','=','files.iid') ->select('items.*','files.hash as file', 'containers.name as box'); foreach ($query_tokens as $token) - $g = $q->where('items.description','like','%'.$token.'%'); + $q = $q->where('items.description','like','%'.$token.'%'); return response()->json($q->get()); } @@ -54,12 +54,17 @@ class ItemController extends Controller $newitem['item_uid'] = $uid; $newitem['wo'] = ""; $item = Item::create($newitem); - $image = $request->file('image'); - $hash = md5(time()); - if(!file_exists('staticimages')) - mkdir('staticimages',0755, true); - $image->move('staticimages', $hash); - $file = File::create(array('hash' => $hash, 'iid'=> $item['iid'])); + + $pos = strpos( $request->get('dataImage') , "," ); + //$head = substr($request->get('dataImage'), 0, $pos); + $image = base64_decode(substr($request->get('dataImage'), $pos+1), true); + if($image) { + $hash = md5(time()); + if (!file_exists('staticimages')) + mkdir('staticimages', 0755, true); + file_put_contents('staticimages/'. $hash, $image); + $file = File::create(array('hash' => $hash, 'iid' => $item['iid'])); + } return response()->json($item, 201); } @@ -67,7 +72,18 @@ class ItemController extends Controller { $eid = Event::where('slug', $event)->first()->eid; $item = Item::where('eid', $eid)->where('item_uid', $id)->first(); - $item->update($request->except(['file','box'])); + $item->update($request->except(['file','box','dataImage'])); + + $pos = strpos( $request->get('dataImage') , "," ); + //$head = substr($request->get('dataImage'), 0, $pos); + $image = base64_decode(substr($request->get('dataImage'), $pos+1), true); + if($image) { + $hash = md5(time()); + if (!file_exists('staticimages')) + mkdir('staticimages', 0755, true); + file_put_contents('staticimages/'. $hash, $image); + $file = File::create(array('hash' => $hash, 'iid' => $item['iid'])); + } return response()->json($item, 200); }