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