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