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