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