repository = $testemail; parent::__construct(); } /** * Display a list of testemail. * * @return Response */ public function index(TestemailRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('testmail::testemail.names').' :: '); return $this->theme->of('testmail::admin.testemail.index')->render(); } /** * Display a list of testemail. * * @return Response */ public function getJson(TestemailRequest $request) { $pageLimit = $request->input('pageLimit'); $testemails = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Testemail\\Testmail\\Repositories\\Presenter\\TestemailListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $testemails['recordsTotal'] = $testemails['meta']['pagination']['total']; $testemails['recordsFiltered'] = $testemails['meta']['pagination']['total']; $testemails['request'] = $request->all(); return response()->json($testemails, 200); } /** * Display testemail. * * @param Request $request * @param Model $testemail * * @return Response */ public function show(TestemailRequest $request, Testemail $testemail) { if (!$testemail->exists) { return response()->view('testmail::admin.testemail.new', compact('testemail')); } Form::populate($testemail); return response()->view('testmail::admin.testemail.show', compact('testemail')); } /** * Show the form for creating a new testemail. * * @param Request $request * * @return Response */ public function create(TestemailRequest $request) { $testemail = $this->repository->newInstance([]); Form::populate($testemail); return response()->view('testmail::admin.testemail.create', compact('testemail')); } /** * Create new testemail. * * @param Request $request * * @return Response */ public function store(TestemailRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $testemail = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('testmail::testemail.name')]), 'code' => 204, 'redirect' => trans_url('/admin/testmail/testemail/'.$testemail->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show testemail for editing. * * @param Request $request * @param Model $testemail * * @return Response */ public function edit(TestemailRequest $request, Testemail $testemail) { Form::populate($testemail); return response()->view('testmail::admin.testemail.edit', compact('testemail')); } /** * Update the testemail. * * @param Request $request * @param Model $testemail * * @return Response */ public function update(TestemailRequest $request, Testemail $testemail) { try { $attributes = $request->all(); $testemail->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('testmail::testemail.name')]), 'code' => 204, 'redirect' => trans_url('/admin/testmail/testemail/'.$testemail->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/testmail/testemail/'.$testemail->getRouteKey()), ], 400); } } /** * Remove the testemail. * * @param Model $testemail * * @return Response */ public function destroy(TestemailRequest $request, Testemail $testemail) { try { $t = $testemail->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('testmail::testemail.name')]), 'code' => 202, 'redirect' => trans_url('/admin/testmail/testemail/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/testmail/testemail/'.$testemail->getRouteKey()), ], 400); } } }