This is a Laravel 11 API project using Sanctum for authentication and MySQL running inside Docker containers.
- Docker & Docker Compose installed
- Composer installed
- Postman or any API testing tool
-
Clone the Repository:
git clone <your-repo-url> cd <your-project-folder>
-
Copy Environment File:
cp .env.example .env
-
Update
.env
File: Ensure the database configuration matches your Docker Compose setup:DB_CONNECTION=mysql DB_HOST=mysql # Service name in docker-compose.yml DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_db_user DB_PASSWORD=your_db_password
-
Start Docker Containers:
docker-compose up -d
-
Run Migrations:
docker exec -it <laravel_container_id> bash php artisan migrate --seed
-
Generate App Key:
php artisan key:generate
Endpoint: POST /api/register
{
"name": "TestUser",
"email": "[email protected]",
"password": "password",
"password_confirmation": "password"
}
Endpoint: POST /api/login
{
"email": "[email protected]",
"password": "password"
}
Response:
{
"token": "your_sanctum_token"
}
Endpoint: POST /api/blogs
Headers:
- Authorization: Bearer
your_sanctum_token
- Accept: application/json
Request Body:
{
"title": "My First Blog",
"content": "This is the content of my first blog post."
}
Endpoint: GET /api/blogs
Headers:
- Authorization: Bearer
your_sanctum_token
Endpoint: GET /api/user
Headers:
- Authorization: Bearer
your_sanctum_token
Run the tests inside the Laravel container:
php artisan test
To stop the Docker containers:
docker-compose down
This project is open-source and available under the MIT License.