Ejemplo n.º 1
0
 public function shorten()
 {
     $validator = $this->validator();
     if ($validator->fails()) {
         return $this->errorResponse(join('<br>', $validator->messages()->all()), 'validation');
     }
     $shortUrl = ShortUrl::where('url', '=', $this->longUrl)->first();
     if ($shortUrl) {
         return $this->successResponse($this->longUrl, $shortUrl->getShortUrl(), $shortUrl->getSecureShortUrl());
     }
     $safeBrowsing = new SafeBrowsing($this->longUrl);
     if (!$safeBrowsing->isSafeSite()) {
         return $this->errorResponse(join(', ', $safeBrowsing->getErrorMessage()), 'safebrowsing');
     }
     $shortUrl = ShortUrl::createFromUrl($this->longUrl);
     if ($shortUrl->save()) {
         return $this->successResponse($this->longUrl, $shortUrl->getShortUrl(), $shortUrl->getSecureShortUrl());
     }
     return $this->errorResponse('Unknown error.');
 }
Ejemplo n.º 2
0
 public function lengthen($short)
 {
     if ($short_url = ShortUrl::findShort($short)) {
         return redirect()->to($short_url->click()->url);
     }
     return redirect()->route('home');
 }