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