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