public function removeEntry(Request $request) { $id = hashids_decode($request->get('content')); $entry = Entry::findOrFail($id); $entry->usave()->delete(); return Response::json(['status' => 'ok']); }
/** * Get the route key for the model. * * @return string */ public function findByEid($eid) { if ($eid != '0') { $eid = hashids_decode($eid); } return $this->findOrNew($eid); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { if ($request->query->has('ntf_read') && $this->auth->check()) { $id = $request->query->get('ntf_read'); $id = hashids_decode($id); NotificationTarget::where('notification_id', $id)->where('user_id', $this->auth->id())->update(['read' => true]); } return $next($request); }
public function removeRelated($related = null) { $related = $related instanceof ContentRelated ?: ContentRelated::findOrFail(hashids_decode(Input::get('id'))); if (Auth::id() == $related->user->getKey()) { $related->delete(); return Response::json(['status' => 'ok']); } return Response::json(['status' => 'error']); }
/** * Create the specified resource. * * @param Request $request * * @return Response */ public function store(AdminMenuWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $attributes['parent_id'] = hashids_decode($attributes['parent_id']); $menu = $this->repository->create($attributes); return response()->json(['message' => trans('messages.success.updated', ['Module' => trans('menu::menu.name')]), 'code' => 204, 'redirect' => trans_url('/admin/menu/submenu/' . $menu->getRouteKey())], 201); } catch (Exception $e) { return response()->json(['message' => $e->getMessage(), 'code' => 400], 400); } }
/** * @return mixed */ public function saveThumbnail() { $id = hashids_decode(request('id')); $content = Content::findOrFail($id); $thumbnails = session('thumbnails', []); if (!$content->canEdit(user())) { return redirect()->route('content_comments', $content->getKey())->with('danger_msg', 'Minął czas dozwolony na edycję treści.'); } $index = (int) request('thumbnail'); if (request()->has('thumbnail') && isset($thumbnails[$index])) { $content->setThumbnail($thumbnails[$index]); } else { $content->removeThumbnail(); } return redirect()->route('content_comments', $content); }
/** * Create the specified resource. * * @param Request $request * * @return Response */ public function store(MenuRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['parent_id'] = hashids_decode($attributes['parent_id']); $menu = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('menu::menu.name')]); $this->responseRedirect = trans_url('/admin/menu/submenu/' . $menu->getRouteKey()); return $this->respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this->respond($request); } }
/** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(AdminMenuWebRequest $request, $id) { $cid = hashids_decode($id); if ($this->repository->findByField('parent_id', $cid)->count() > 0) { return response()->json(['message' => 'Child menu exists.', 'type' => 'warning', 'title' => 'Warning'], 409); } try { $menu = $this->repository->find($id); $menu->delete(); return response()->json(['message' => trans('messages.success.deleted', ['Module' => trans('menu::menu.name')]), 'code' => 202, 'redirect' => trans_url('/admin/menu/menu/0')], 202); } catch (Exception $e) { return response()->json(['message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/menu/menu/' . $menu->getRouteKey())], 400); } }
public function removeEntry(Request $request, $id = null) { $id = hashids_decode($id ? $id : Input::get('id')); $class = $request->input('type') == 'entry_reply' ? EntryReply::class : Entry::class; $entry = $class::findOrFail($id); if ($entry->canRemove()) { if ($entry->delete()) { return Response::json(['status' => 'ok']); } } return Response::json(['status' => 'error'], 500); }
public function getParentChild($id, $array) { foreach ($array as $node) { $this->tempHolder[hashids_decode($id)][] = array_get($node, 'id'); if (isset($node['children'])) { $this->getParentChild(array_get($node, 'id'), $node['children']); } } }
/** * Select root menu. * * @return result */ public function updateParent($parent, $children) { foreach ($children as $key => $val) { $this->update(['parent_id' => hashids_decode($parent), 'order' => $key], hashids_decode($val)); } }
/** * @return mixed */ public function saveThumbnail(Request $request) { $id = hashids_decode($request->input('id')); $content = Content::findOrFail($id); $thumbnails = Session::get('thumbnails'); if (!$content->canEdit(Auth::user())) { return Redirect::route('content_comments', $content->getKey())->with('danger_msg', 'Minął czas dozwolony na edycję treści.'); } $index = (int) Input::get('thumbnail'); if (Input::has('thumbnail') && isset($thumbnails[$index])) { $content->setThumbnail($thumbnails[$index]); } else { $content->removeThumbnail(); } return Redirect::route('content_comments', $content); }
public function removeComment(Request $request) { $class = Input::get('type') == 'comment' ? Comment::class : CommentReply::class; $id = hashids_decode($request->input('id')); $comment = $class::findOrFail($id); if ($comment->canRemove()) { $comment->delete(); return Response::json(['status' => 'ok']); } return Response::json(['status' => 'error']); }
/** * Get the route key for the model. * * @return string */ public function findOrNew($id, $columns = ['*']) { $id = hashids_decode($id); $id = empty($id) ? 0 : $id; return parent::findOrNew($id, $columns); }
/** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(MenuRequest $request, $id) { $cid = hashids_decode($id); if ($this->repository->findByField('parent_id', $cid)->count() > 0) { return Response::json(['message' => 'Child menu exists.', 'type' => 'warning', 'title' => 'Warning'], 409); } try { $menu = $this->repository->find($id); $menu->delete(); return Response::json(['message' => 'Menu deleted sucessfully', 'type' => 'success', 'title' => 'Success'], 201); } catch (Exception $e) { return Response::json(['message' => $e->getMessage(), 'type' => 'error', 'title' => 'Error'], 400); } }
/** * @return \Symfony\Component\HttpFoundation\Response */ public function softRemoveContent() { $id = hashids_decode(request('id')); $content = Content::findOrFail($id); if ($content->canRemove(user())) { $content->deletedBy()->associate(user()); $content->save(); $content->delete(); return Response::json(['status' => 'ok']); } return Response::json(['status' => 'error']); }
/** * Get decoded folder. * * @param array $folder * * @return string */ function folder_decode($folder) { $formatFolder = function ($folder) { return str_pad($folder[0], 4, '0', STR_PAD_LEFT) . '/' . str_pad($folder[1], 2, '0', STR_PAD_LEFT) . '/' . str_pad($folder[2], 2, '0', STR_PAD_LEFT) . '/' . str_pad($folder[3], 9, '0', STR_PAD_LEFT); }; $arr = explode('/', $folder); if (count($arr) == 1) { $folder = hashids_decode($arr[0]); return $formatFolder($folder); } }