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