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