This PHP code sample demonstrates how to build an API server using Laravel that is secure by design. This Laravel code sample uses the Auth0 Laravel SDK.
Visit the "Laravel/PHP Code Samples: API Security in Action" section of the "Auth0 Developer Resources" to explore how you can secure Laravel applications written in PHP by implementing endpoint protection and authorization with Auth0.
Auth0 is a flexible drop-in solution to add authentication and authorization services to your applications. Your team and organization can avoid the cost, time, and risk that come with building your own solution to authenticate and authorize users. We offer tons of guidance and SDKs for you to get started and integrate Auth0 into your stack easily.
Create a .env
file under the root project directory:
touch .env
Populate it with the following environment variables:
APP_PORT=6060
CLIENT_ORIGIN_URL=http://localhost:4040
Install the project's dependencies running the following command.
composer install
Execute the following command to run the Laravel API server using Sail:
./vendor/bin/sail up
Otherwise, use the following command to run the API server using Composer:
php artisan serve --port 6060