repository = $ex; } /** * Display a list of ex. * * @return Response */ public function index(ExAdminRequest $request) { $exes = $this->repository->setPresenter('\\Developer\\DataTable\\Repositories\\Presenter\\ExListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this ->theme->prependTitle(trans('data_table::ex.names').' :: '); $view = $this->theme->of('data_table::admin.ex.index')->render(); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('data_table::ex.name')]); $this->responseData = $exes['data']; $this->responseMeta = $exes['meta']; $this->responseView = $view; $this->responseRedirect = ''; return $this->respond($request); } /** * Display ex. * * @param Request $request * @param int $id * * @return Response */ public function show(ExAdminRequest $request, Ex $ex) { if (!$ex->exists) { $this->responseCode = 404; $this->responseMessage = trans('messages.success.notfound', ['Module' => trans('data_table::ex.name')]); $this->responseView = view('data_table::admin.ex.new'); return $this -> respond($request); } Form::populate($ex); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('data_table::ex.name')]); $this->responseData = $ex; $this->responseView = view('data_table::admin.ex.show', compact('ex')); return $this -> respond($request); } /** * Show the form for creating a new ex. * * @param Request $request * * @return Response */ public function create(ExAdminRequest $request) { $ex = $this->repository->newInstance([]); Form::populate($ex); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('data_table::ex.name')]); $this->responseData = $ex; $this->responseView = view('data_table::admin.ex.create', compact('ex')); return $this -> respond($request); } /** * Create new ex. * * @param Request $request * * @return Response */ public function store(ExAdminRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $ex = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('data_table::ex.name')]); $this->responseData = $ex; $this->responseMeta = ''; $this->responseRedirect = trans_url('/admin/data_table/ex/'.$ex->getRouteKey()); $this->responseView = view('data_table::admin.ex.create', compact('ex')); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this -> respond($request); } } /** * Show ex for editing. * * @param Request $request * @param int $id * * @return Response */ public function edit(ExAdminRequest $request, Ex $ex) { Form::populate($ex); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('data_table::ex.name')]); $this->responseData = $ex; $this->responseView = view('data_table::admin.ex.edit', compact('ex')); return $this -> respond($request); } /** * Update the ex. * * @param Request $request * @param int $id * * @return Response */ public function update(ExAdminRequest $request, Ex $ex) { try { $attributes = $request->all(); $ex->update($attributes); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('data_table::ex.name')]); $this->responseData = $ex; $this->responseRedirect = trans_url('/admin/data_table/ex/'.$ex->getRouteKey()); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/data_table/ex/'.$ex->getRouteKey()); return $this -> respond($request); } } /** * Remove the ex. * * @param int $id * * @return Response */ public function destroy(ExAdminRequest $request, Ex $ex) { try { $t = $ex->delete(); $this->responseCode = 202; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('data_table::ex.name')]); $this->responseRedirect = trans_url('/admin/data_table/ex/0'); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/data_table/ex/'.$ex->getRouteKey()); return $this -> respond($request); } } }