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