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