refactor items table
This commit is contained in:
parent
836fb96f42
commit
8ab469e017
4 changed files with 56 additions and 22 deletions
|
@ -38,7 +38,7 @@ class ItemController extends Controller
|
|||
public function showOneItem($event, $id)
|
||||
{
|
||||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
return response()->json(Item::byEvent($eid)->where('item_uid', '=', $id)->first());
|
||||
return response()->json(Item::byEvent($eid)->where('uid', '=', $id)->first());
|
||||
}
|
||||
|
||||
public function create($event, Request $request)
|
||||
|
@ -46,8 +46,6 @@ class ItemController extends Controller
|
|||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
$newitem = $request->except(['dataImage']);
|
||||
$newitem['eid'] = "".$eid;
|
||||
$newitem['wo'] = "";
|
||||
$newitem['wann'] = "";
|
||||
$item = Item::create($newitem);
|
||||
|
||||
if ($request->get('dataImage')) {
|
||||
|
@ -69,7 +67,7 @@ class ItemController extends Controller
|
|||
public function update($event, $id, Request $request)
|
||||
{
|
||||
$eid = Event::where('slug', $event)->first()->eid;
|
||||
$item = Item::where('eid', $eid)->where('item_uid', $id)->first();
|
||||
$item = Item::where('eid', $eid)->where('uid', $id)->first();
|
||||
$item->update($request->except(['file', 'box', 'dataImage']));
|
||||
|
||||
if($request->get('returned')===true){
|
||||
|
@ -89,13 +87,13 @@ class ItemController extends Controller
|
|||
$item['file'] = $hash;
|
||||
}
|
||||
}
|
||||
return response()->json(Item::find($item['item_uid']), 200);
|
||||
return response()->json(Item::find($item['uid']), 200);
|
||||
}
|
||||
|
||||
public function delete($event, $id)
|
||||
{
|
||||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
Item::where('eid', $eid)->where('item_uid', $id)->first()->delete();
|
||||
Item::where('eid', $eid)->where('uid', $id)->first()->delete();
|
||||
return response()->json(array("status"=>'Deleted Successfully'), 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class Item extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'iid', 'item_uid', 'description', 'wann', 'wo', 'eid', 'cid', 'returned_at'
|
||||
'iid', 'uid', 'description', 'eid', 'cid', 'returned_at'
|
||||
];
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ class Item extends Model
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['created_at','updated_at', 'deleted_at', 'returned_at', 'eid', 'iid', 'wann', 'wo'];
|
||||
protected $hidden = ['created_at','updated_at', 'deleted_at', 'returned_at', 'eid', 'iid'];
|
||||
|
||||
public static function restored($callback)
|
||||
{
|
||||
|
@ -34,8 +34,8 @@ class Item extends Model
|
|||
|
||||
public static function create(array $attributes = [])
|
||||
{
|
||||
$uid = static::query()->where('eid',$attributes['eid'])->max('item_uid') + 1;
|
||||
$attributes['item_uid'] = $uid;
|
||||
$uid = static::query()->where('eid',$attributes['eid'])->max('uid') + 1;
|
||||
$attributes['uid'] = $uid;
|
||||
static::query()->create($attributes);
|
||||
return Item::find($uid);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue