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