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