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