repository = $campaign; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\Campaign\Repositories\Criteria\CampaignResourceCriteria::class); } /** * Display a list of campaign. * * @return Response */ public function index(CampaignRequest $request) { return $this->repository ->setPresenter(\Litepie\Campaign\Repositories\Presenter\CampaignPresenter::class) ->paginate(); } /** * Display campaign. * * @param Request $request * @param Model $campaign * * @return Response */ public function show(CampaignRequest $request, Campaign $campaign) { return $campaign->setPresenter(\Litepie\Campaign\Repositories\Presenter\CampaignListPresenter::class); ; } /** * Create new campaign. * * @param Request $request * * @return Response */ public function store(CampaignRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('campaign::campaign.name')]); $code = 204; $status = 'success'; $url = guard_url('campaign/campaign/' . $campaign->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('campaign/campaign'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the campaign. * * @param Request $request * @param Model $campaign * * @return Response */ public function update(CampaignRequest $request, Campaign $campaign) { try { $data = $request->all(); $campaign->update($data); $message = trans('messages.success.updated', ['Module' => trans('campaign::campaign.name')]); $code = 204; $status = 'success'; $url = guard_url('campaign/campaign/' . $campaign->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('campaign/campaign/' . $campaign->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the campaign. * * @param Model $campaign * * @return Response */ public function destroy(CampaignRequest $request, Campaign $campaign) { try { $campaign->delete(); $message = trans('messages.success.deleted', ['Module' => trans('campaign::campaign.name')]); $code = 202; $status = 'success'; $url = guard_url('campaign/campaign/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('campaign/campaign/' . $campaign->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }