add file upload to edit endpoint
This commit is contained in:
parent
906201313e
commit
b771a88bf8
1 changed files with 24 additions and 8 deletions
|
@ -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');
|
||||
|
||||
$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);
|
||||
$image->move('staticimages', $hash);
|
||||
$file = File::create(array('hash' => $hash, 'iid'=> $item['iid']));
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue