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