repository = $sale; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Lavalite\Sale\Repositories\Criteria\SaleResourceCriteria::class); } /** * Display a list of sale. * * @return Response */ public function index(SaleRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Lavalite\Sale\Repositories\Presenter\SalePresenter::class) ->$function(); } $sales = $this->repository->paginate(); return $this->response->title(trans('sale::sale.names')) ->view('sale::sale.index', true) ->data(compact('sales')) ->output(); } /** * Display sale. * * @param Request $request * @param Model $sale * * @return Response */ public function show(SaleRequest $request, Sale $sale) { if ($sale->exists) { $view = 'sale::sale.show'; } else { $view = 'sale::sale.new'; } return $this->response->title(trans('app.view') . ' ' . trans('sale::sale.name')) ->data(compact('sale')) ->view($view, true) ->output(); } /** * Show the form for creating a new sale. * * @param Request $request * * @return Response */ public function create(SaleRequest $request) { $sale = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('sale::sale.name')) ->view('sale::sale.create', true) ->data(compact('sale')) ->output(); } /** * Create new sale. * * @param Request $request * * @return Response */ public function store(SaleRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $sale = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('sale::sale.name')])) ->code(204) ->status('success') ->url(guard_url('sale/sale/' . $sale->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/sale/sale')) ->redirect(); } } /** * Show sale for editing. * * @param Request $request * @param Model $sale * * @return Response */ public function edit(SaleRequest $request, Sale $sale) { return $this->response->title(trans('app.edit') . ' ' . trans('sale::sale.name')) ->view('sale::sale.edit', true) ->data(compact('sale')) ->output(); } /** * Update the sale. * * @param Request $request * @param Model $sale * * @return Response */ public function update(SaleRequest $request, Sale $sale) { try { $attributes = $request->all(); $sale->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('sale::sale.name')])) ->code(204) ->status('success') ->url(guard_url('sale/sale/' . $sale->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('sale/sale/' . $sale->getRouteKey())) ->redirect(); } } /** * Remove the sale. * * @param Model $sale * * @return Response */ public function destroy(SaleRequest $request, Sale $sale) { try { $sale->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('sale::sale.name')])) ->code(202) ->status('success') ->url(guard_url('sale/sale/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('sale/sale/' . $sale->getRouteKey())) ->redirect(); } } /** * Remove multiple sale. * * @param Model $sale * * @return Response */ public function delete(SaleRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('sale::sale.name')])) ->status("success") ->code(202) ->url(guard_url('sale/sale')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/sale/sale')) ->redirect(); } } /** * Restore deleted sales. * * @param Model $sale * * @return Response */ public function restore(SaleRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('sale::sale.name')])) ->status("success") ->code(202) ->url(guard_url('/sale/sale')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/sale/sale/')) ->redirect(); } } }