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