/** * Show page (get). * * @Get("show/{hash}", as="pastebin.show") * * @param string $hash * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function getShow($hash) { $paste_bin = $this->pasteBin->where('hash', $hash)->get()->first(); if (!isset($paste_bin)) { abort(404); } $isProtect = $paste_bin->protect === true || $paste_bin->protect === '1'; $robots = $isProtect ? 'noindex,nofollow' : null; $showAlert = $isProtect; return view('pastebins.show', compact('paste_bin', 'robots', 'showAlert')); }
/** * pastebin/create API. * * @Any("create", as="api.pastebin.create") * * @return \Illuminate\Http\JsonResponse */ public function anyCreate() { try { $hash = str_random(5); $insert = []; foreach (['description', 'code', 'protect'] as $v) { $insert[$v] = $this->request($v); } $insert['hash'] = $hash; $validate = $this->pasteBin->insert($insert, ['save' => true]); if ($validate === true) { $data = $this->pasteBin->where('hash', $hash)->get()->first(); return $this->onSuccess($data); } throw new RuntimeException($validate->errors()->first(), 400); } catch (Exception $e) { return $this->onError($e); } }