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