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