repository = $unit; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Inventory\Item\Repositories\Criteria\UnitResourceCriteria::class); } /** * Display a list of unit. * * @return Response */ public function index(UnitRequest $request) { return $this->repository ->setPresenter(\Inventory\Item\Repositories\Presenter\UnitPresenter::class) ->paginate(); } /** * Display unit. * * @param Request $request * @param Model $unit * * @return Response */ public function show(UnitRequest $request, Unit $unit) { return $unit->setPresenter(\Inventory\Item\Repositories\Presenter\UnitListPresenter::class); ; } /** * Create new unit. * * @param Request $request * * @return Response */ public function store(UnitRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('item::unit.name')]); $code = 204; $status = 'success'; $url = guard_url('item/unit/' . $unit->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('item/unit'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the unit. * * @param Request $request * @param Model $unit * * @return Response */ public function update(UnitRequest $request, Unit $unit) { try { $data = $request->all(); $unit->update($data); $message = trans('messages.success.updated', ['Module' => trans('item::unit.name')]); $code = 204; $status = 'success'; $url = guard_url('item/unit/' . $unit->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('item/unit/' . $unit->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the unit. * * @param Model $unit * * @return Response */ public function destroy(UnitRequest $request, Unit $unit) { try { $unit->delete(); $message = trans('messages.success.deleted', ['Module' => trans('item::unit.name')]); $code = 202; $status = 'success'; $url = guard_url('item/unit/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('item/unit/' . $unit->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }