/** * Short url. * * @Get("{hash}", as="shorturl") * * @param string $hash * * @return \Illuminate\Http\RedirectResponse */ public function getShortUrl($hash) { $result = $this->shortURL->where('hash', $hash)->get()->first(); if (!isset($result)) { abort(404); } return redirect()->to($result->url); }
/** * Create new short url data. * * @return mixed */ protected function createData() { $hash = str_random(5); $url = 'https://hiroto-k.net/'; $this->shortURL->hash = $hash; $this->shortURL->url = $url; $this->shortURL->save(); return $this->shortURL->where('hash', $hash)->where('url', $url)->get()->first(); }