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