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