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