URL Shortener 1.0
A Laravel-based URL shortener application
Chargement...
Recherche...
Aucune correspondance
RedirectController.php
Aller à la documentation de ce fichier.
1<?php
2
4
6use Illuminate\Http\RedirectResponse;
7use Illuminate\Contracts\View\View;
8use Illuminate\Http\Response;
9
20{
32 public function redirect(string $code): View|RedirectResponse|Response
33 {
34 $shortUrl = ShortUrl::withTrashed()
35 ->where('code', $code)
36 ->first();
37
38 if (! $shortUrl) {
39 abort(404);
40 }
41
42 if ($shortUrl->trashed()) {
43 return response()->view('shorturls.deleted', compact('shortUrl'), 410);
44 }
45
46 return redirect()->away($shortUrl->original_url);
47 }
48}
redirect(string $code)
Redirect to the original URL corresponding to a unique code.