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