This is a minimal URL shortener built with Laravel 12 and FilamentPHP 4 based on the starter repository provided for the interview.
-
GET /
Displays a minimal HTML form where anyone can submit a long URL. -
POST /
Validates the submitted URL and returns a shortened URL.
Validation rules:
requiredurl(basic URL syntax)active_url(domain must exist, DNS-level check)max:2048
If the URL already exists in the database, the existing short code is reused. Otherwise, a new unique short code is generated.
GET /r/{code}
Looks up the original URL by its short code and redirects to it usingredirect()->away().
Model: App\Models\ShortUrl
- Table:
short_urls - Columns:
idcode(unique, short string)url(original URL)created_at,updated_at
The model contains a helper method generateUniqueCode() that generates a random 6-character code and ensures uniqueness in the database.
- Admin URL:
/admin - Default user:
admin@localhost/abcd1234(created from the provided setup script or artisan command) - Resource:
App\Filament\Resources\ShortUrls\ShortUrlResource
The resource provides:
- List view of all short URLs (ID, code, original URL, created_at)
- Create / Edit forms with the same validation as the public form:
- required, url, activeUrl(), max length
- Delete & bulk delete actions
Feature tests: tests/Feature/UrlShortenerTest.php
Covered scenarios:
- A long URL submitted on
/creates ashort_urlsrecord and redirects back to/with the shortened URL in the session. GET /r/{code}redirects to the original URL stored for that code.- An unknown short code returns a 404 response.
All tests can be executed with: php artisan test.
The repository already contains a run.sh helper script as provided in the exercise.
First install PHP dependencies:
composer install
Then run:
./run.sh
The script will:
- copy
.env.exampleto.env - generate the application key
- run the database migrations
- create the admin user (
admin@localhost/abcd1234) - start the development server
composer installcp .env.example .env
Configure the database (SQLite is used in this implementation).php artisan key:generatephp artisan migratephp artisan make:filament-user --name=admin --email=admin@localhost --password=abcd1234php artisan serve
Then open:
- Public URL shortener: http://localhost:8000/
- Admin panel: http://localhost:8000/admin
- Expiration / soft delete for short URLs
- Click statistics per code (number of redirects)
- Rate limiting or spam protection on the public form
- Configurable short code length or human-readable codes