This commit is contained in:
j3d1 2020-01-18 20:53:46 +01:00
parent d4e0d3859e
commit 836fb96f42
4 changed files with 77 additions and 27 deletions

View file

@ -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();
}
}