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