A ready-to-use starter for creating an API with Laravel 12, including Fortify for authentication and Sanctum for API authentication.
- Laravel 12: The latest PHP framework for web application development.
- Fortify: For user authentication.
- Sanctum: For API authentication.
- JSON Responses: API responses are formatted in JSON.
- PHP >= 8.1
- Composer
- Database (MySQL, PostgreSQL, SQLite, etc.)
- Node.js (for frontend dependencies if needed)
- Clone the repository:
git clone https://github.com/votre-utilisateur/laravel-12-api-starter.git
cd laravel-12-api-starter- Install PHP dependencies:
composer install- Copy the environment file and configure it:
cp .env.example .env- Configure your
.envfile with your database information and other necessary settings.
Generate the application key:
php artisan key\:generate- Run migrations to create the database tables:
php artisan migrate(Optional) Install frontend dependencies if needed:
npm install
npm run devStart the development server:
php artisan serveAccess the API via http://localhost:8000.
Fortify is already configured for user authentication. You can customize the views and routes as needed. Sanctum is configured for API authentication. Ensure to set up the appropriate middleware to protect your API routes.
Here are some example API requests you can use:
Registration:
POST /api/register
Content-Type: application/json{
"name": "John Doe",
"email": "john@example.com",
"password": "password",
"password_confirmation": "password"
}Login:
POST /api/login
Content-Type: application/json{
"email": "john@example.com",
"password": "password"
}Access a protected resource:
GET /api/user
Authorization: Bearer {token}Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for more details.