Protect your Laravel API
This simple Laravel application demonstrates how to implement API key verification using Unkey. The application has both public and protected routes, with the protected route requiring a valid API key.
API ID
.access-unkeyed-route
withAuth
permission for the role.Clone this repository:
1git clone https://github.com/harshsbhat/unkey-laravel-example.git2cd unkey-laravel-example
Install dependencies:
1composer install
Generate an application key: Laravel requires an application key for encryption. You can generate one by running:
1php artisan key:generate
Set up your environment variables: Copy the .env.example into a .env file using cp .env.example .env
in the project root and add the following variables.
Get the Unkey API ID and Unkey rootkey from unkey dashboard
1UNKEY_API_ID=your_unkey_api_id2UNKEY_ROOT_KEY=your_unkey_root_key
Run the project. It should start on PORT 8000
1php artisan serve
http://localhost:8000/public
to access the public route.http://localhost:8000/protected
with an Authorization
header containing your API key.1curl http://localhost:8000/public
1curl -H "Authorization: Bearer <api_key>" http://localhost:8000/protected
2500 verifications and 100K successful rate‑limited requests per month. No CC required.