repository = $stock; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Survey\Stock\Repositories\Criteria\StockResourceCriteria::class); } /** * Display a list of stock. * * @return Response */ public function index(StockRequest $request) { return $this->repository ->setPresenter(\Survey\Stock\Repositories\Presenter\StockPresenter::class) ->paginate(); } /** * Display stock. * * @param Request $request * @param Model $stock * * @return Response */ public function show(StockRequest $request, Stock $stock) { return $stock->setPresenter(\Survey\Stock\Repositories\Presenter\StockListPresenter::class); ; } /** * Create new stock. * * @param Request $request * * @return Response */ public function store(StockRequest $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('stock::stock.name')]); $code = 204; $status = 'success'; $url = guard_url('stock/stock/' . $stock->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('stock/stock'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the stock. * * @param Request $request * @param Model $stock * * @return Response */ public function update(StockRequest $request, Stock $stock) { try { $data = $request->all(); $stock->update($data); $message = trans('messages.success.updated', ['Module' => trans('stock::stock.name')]); $code = 204; $status = 'success'; $url = guard_url('stock/stock/' . $stock->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('stock/stock/' . $stock->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the stock. * * @param Model $stock * * @return Response */ public function destroy(StockRequest $request, Stock $stock) { try { $stock->delete(); $message = trans('messages.success.deleted', ['Module' => trans('stock::stock.name')]); $code = 202; $status = 'success'; $url = guard_url('stock/stock/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('stock/stock/' . $stock->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); } }