cleanup
This commit is contained in:
parent
d4e0d3859e
commit
836fb96f42
4 changed files with 77 additions and 27 deletions
|
@ -37,6 +37,6 @@ class Container extends Model
|
|||
static function find($id){
|
||||
return Container::leftJoin('items','items.cid','=','containers.cid')
|
||||
->select('containers.cid', 'name', DB::raw('count(items.iid) as itemCount'))
|
||||
->groupBy('containers.cid', 'name')->where('items.cid', '=', $id)->first();
|
||||
->groupBy('containers.cid', 'name')->where(Container::primaryKey, '=', $id)->first();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,7 @@ class ItemController extends Controller
|
|||
public function showByEvent($event)
|
||||
{
|
||||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
$q = Item::where('eid','=',$eid)->whereNull('returned_at')
|
||||
->join('containers','items.cid','=','containers.cid')
|
||||
->leftJoin('currentfiles','items.iid','=','currentfiles.iid')
|
||||
->select('items.*','currentfiles.hash as file', 'containers.name as box');
|
||||
$q = Item::byEvent($eid);
|
||||
return response()->json($q->get());
|
||||
}
|
||||
|
||||
|
@ -31,29 +28,26 @@ class ItemController extends Controller
|
|||
{
|
||||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
$query_tokens = explode(" ",base64_decode ( $query , true));
|
||||
$q = Item::where('eid','=',$eid)->whereNull('returned_at')
|
||||
->join('containers','items.cid','=','containers.cid')
|
||||
->leftJoin('currentfiles','items.iid','=','currentfiles.iid')
|
||||
->select('items.*','currentfiles.hash as file', 'containers.name as box');
|
||||
$q = Item::byEvent($eid);
|
||||
foreach ($query_tokens as $token)
|
||||
$q = $q->where('items.description','like','%'.$token.'%');
|
||||
if(!empty($token))
|
||||
$q = $q->where('items.description','like','%'.$token.'%');
|
||||
return response()->json($q->get());
|
||||
}
|
||||
|
||||
public function showOneItem($event, $id)
|
||||
{
|
||||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
return response()->json(Item::find($id));
|
||||
return response()->json(Item::byEvent($eid)->where('item_uid', '=', $id)->first());
|
||||
}
|
||||
|
||||
public function create($event, Request $request)
|
||||
{
|
||||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
$uid = Item::withTrashed()->where('eid',$eid)->max('item_uid') + 1;
|
||||
$newitem = $request->except(['dataImage']);
|
||||
$newitem['eid'] = "".$eid;
|
||||
$newitem['item_uid'] = $uid;
|
||||
$newitem['wo'] = "";
|
||||
$newitem['wann'] = "";
|
||||
$item = Item::create($newitem);
|
||||
|
||||
if ($request->get('dataImage')) {
|
||||
|
@ -95,7 +89,7 @@ class ItemController extends Controller
|
|||
$item['file'] = $hash;
|
||||
}
|
||||
}
|
||||
return response()->json($item, 200);
|
||||
return response()->json(Item::find($item['item_uid']), 200);
|
||||
}
|
||||
|
||||
public function delete($event, $id)
|
||||
|
|
31
app/Item.php
31
app/Item.php
|
@ -31,4 +31,35 @@ class Item extends Model
|
|||
public static function restored($callback)
|
||||
{
|
||||
}
|
||||
|
||||
public static function create(array $attributes = [])
|
||||
{
|
||||
$uid = static::query()->where('eid',$attributes['eid'])->max('item_uid') + 1;
|
||||
$attributes['item_uid'] = $uid;
|
||||
static::query()->create($attributes);
|
||||
return Item::find($uid);
|
||||
}
|
||||
|
||||
protected static function extended($columns=Array()){
|
||||
return Item::whereNull('returned_at')
|
||||
->join('containers','items.cid','=','containers.cid')
|
||||
->leftJoin('currentfiles','items.iid','=','currentfiles.iid');
|
||||
}
|
||||
|
||||
static function byEvent($eid){
|
||||
return Item::extended()->where('eid','=',$eid)
|
||||
->select('items.*','currentfiles.hash as file', 'containers.name as box');
|
||||
}
|
||||
|
||||
static function all($columns=Array()){
|
||||
return Item::extended($columns)
|
||||
->select('items.*','currentfiles.hash as file', 'containers.name as box')
|
||||
->get();
|
||||
}
|
||||
|
||||
static function find($id){
|
||||
return Item::extended()
|
||||
->select('items.*','currentfiles.hash as file', 'containers.name as box')
|
||||
->where('items.iid', '=', $id)->first();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue