Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * 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();
 }
Exemplo n.º 3
0
 /**
  * Delete page (post).
  *
  * @Post("delete/{id}", as="admin.shorturl.delete")
  *
  * @param string $id
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function postDelete($id)
 {
     $shorturl = $this->shortURL->find($id);
     if (!isset($shorturl)) {
         abort(404);
     }
     $shorturl->delete();
     return redirect('admin/shorturl')->with('message', '削除しました。');
 }
Exemplo n.º 4
0
 /**
  * Test insert method.
  *
  * @dataProvider insertDataProvider
  *
  * @param mixed $hash
  * @param mixed $url
  * @param bool  $hasError
  */
 public function testInsert($hash, $url, $hasError)
 {
     $data = compact('hash', 'url');
     $response = $this->shortURL->insert($data);
     $this->checkError($response, $hasError);
 }