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