repository = $announcement; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Kscc\Announcement\Repositories\Criteria\AnnouncementResourceCriteria::class); } /** * Display a list of announcement. * * @return Response */ public function index(AnnouncementRequest $request) { return $this->repository ->setPresenter(\Kscc\Announcement\Repositories\Presenter\AnnouncementPresenter::class) ->paginate(); } /** * Display announcement. * * @param Request $request * @param Model $announcement * * @return Response */ public function show(AnnouncementRequest $request, Announcement $announcement) { return $announcement->setPresenter(\Kscc\Announcement\Repositories\Presenter\AnnouncementListPresenter::class); ; } /** * Create new announcement. * * @param Request $request * * @return Response */ public function store(AnnouncementRequest $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('announcement::announcement.name')]); $code = 204; $status = 'success'; $url = guard_url('announcement/announcement/' . $announcement->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('announcement/announcement'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the announcement. * * @param Request $request * @param Model $announcement * * @return Response */ public function update(AnnouncementRequest $request, Announcement $announcement) { try { $data = $request->all(); $announcement->update($data); $message = trans('messages.success.updated', ['Module' => trans('announcement::announcement.name')]); $code = 204; $status = 'success'; $url = guard_url('announcement/announcement/' . $announcement->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('announcement/announcement/' . $announcement->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the announcement. * * @param Model $announcement * * @return Response */ public function destroy(AnnouncementRequest $request, Announcement $announcement) { try { $announcement->delete(); $message = trans('messages.success.deleted', ['Module' => trans('announcement::announcement.name')]); $code = 202; $status = 'success'; $url = guard_url('announcement/announcement/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('announcement/announcement/' . $announcement->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); } }