/php-laravel12-starter

A ready-to-use starter for creating an API with Laravel 12, including Fortify for authentication and Sanctum for API authentication. This project is configured to provide responses in JSON and is ideal for quickly starting a robust and secure API project.

Primary LanguagePHPMIT LicenseMIT

Laravel 12 API Starter

A ready-to-use starter for creating an API with Laravel 12, including Fortify for authentication and Sanctum for API authentication.

Features

  • 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.

Prerequisites

  • PHP >= 8.1
  • Composer
  • Database (MySQL, PostgreSQL, SQLite, etc.)
  • Node.js (for frontend dependencies if needed)

Installation

  1. Clone the repository:
git clone https://github.com/votre-utilisateur/laravel-12-api-starter.git
cd laravel-12-api-starter
  1. Install PHP dependencies:
composer install
  1. Copy the environment file and configure it:
cp .env.example .env
  1. Configure your .env file with your database information and other necessary settings.

Generate the application key:

php artisan key\:generate
  1. Run migrations to create the database tables:
php artisan migrate

(Optional) Install frontend dependencies if needed:

npm install
npm run dev

Usage

Start the development server:

php artisan serve

Access the API via http://localhost:8000.

Fortify and Sanctum Configuration

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.

Example API Requests

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}

Contribution

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.