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