repository = $campaign_database; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Bixo\Campaign\Repositories\Criteria\CampaignDatabaseResourceCriteria::class); } /** * Display a list of campaign_database. * * @return Response */ public function index(CampaignDatabaseRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Bixo\Campaign\Repositories\Presenter\CampaignDatabasePresenter::class) ->$function(); } $campaign_databases = $this->repository->paginate(); return $this->response->setMetaTitle(trans('campaign::campaign_database.names')) ->view('campaign::campaign_database.index', true) ->data(compact('campaign_databases', 'view')) ->output(); } /** * Display campaign_database. * * @param Request $request * @param Model $campaign_database * * @return Response */ public function show(CampaignDatabaseRequest $request, CampaignDatabase $campaign_database) { if ($campaign_database->exists) { $view = 'campaign::campaign_database.show'; } else { $view = 'campaign::campaign_database.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('campaign::campaign_database.name')) ->data(compact('campaign_database')) ->view($view, true) ->output(); } /** * Show the form for creating a new campaign_database. * * @param Request $request * * @return Response */ public function create(CampaignDatabaseRequest $request) { $campaign_database = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('campaign::campaign_database.name')) ->view('campaign::campaign_database.create', true) ->data(compact('campaign_database')) ->output(); } /** * Create new campaign_database. * * @param Request $request * * @return Response */ public function store(CampaignDatabaseRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $campaign_database = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('campaign::campaign_database.name')])) ->code(204) ->status('success') ->url(guard_url('campaign/campaign_database/' . $campaign_database->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/campaign/campaign_database')) ->redirect(); } } /** * Show campaign_database for editing. * * @param Request $request * @param Model $campaign_database * * @return Response */ public function edit(CampaignDatabaseRequest $request, CampaignDatabase $campaign_database) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('campaign::campaign_database.name')) ->view('campaign::campaign_database.edit', true) ->data(compact('campaign_database')) ->output(); } /** * Update the campaign_database. * * @param Request $request * @param Model $campaign_database * * @return Response */ public function update(CampaignDatabaseRequest $request, CampaignDatabase $campaign_database) { try { $attributes = $request->all(); $campaign_database->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('campaign::campaign_database.name')])) ->code(204) ->status('success') ->url(guard_url('campaign/campaign_database/' . $campaign_database->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('campaign/campaign_database/' . $campaign_database->getRouteKey())) ->redirect(); } } /** * Remove the campaign_database. * * @param Model $campaign_database * * @return Response */ public function destroy(CampaignDatabaseRequest $request, CampaignDatabase $campaign_database) { try { $campaign_database->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('campaign::campaign_database.name')])) ->code(202) ->status('success') ->url(guard_url('campaign/campaign_database/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('campaign/campaign_database/' . $campaign_database->getRouteKey())) ->redirect(); } } /** * Remove multiple campaign_database. * * @param Model $campaign_database * * @return Response */ public function delete(CampaignDatabaseRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('campaign::campaign_database.name')])) ->status("success") ->code(202) ->url(guard_url('campaign/campaign_database')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/campaign/campaign_database')) ->redirect(); } } /** * Restore deleted campaign_databases. * * @param Model $campaign_database * * @return Response */ public function restore(CampaignDatabaseRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('campaign::campaign_database.name')])) ->status("success") ->code(202) ->url(guard_url('/campaign/campaign_database')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/campaign/campaign_database/')) ->redirect(); } } }