- PHP: ^8.2
- MySQL: ^8.0
-
Clone the repository:
git clone https://github.com/Raffian-moin/Product-management-API.git
-
Navigate to the project directory:
cd your_project_directory
-
Create the environment file:
- Copy .env.example to .env:
cp .env.example .env
-
Install dependencies:
composer install
-
Set up the database:
- Create a new database in your DBMS called product_management.
-
Generate the application key:
php artisan key:generate
-
Run database migrations:
php artisan migrate
-
Seed the database:
php artisan db:seed
This will create the following users:
- Admin: admin@mail.com
- Customer: customer@mail.com
- Password: 12345678
- Register: POST /api/auth/register
- Login: POST /api/auth/login
- Logout: POST /api/auth/logout
- Refresh Token: POST /api/auth/refresh
- Get Authenticated User: GET /api/auth/me
- List Products: GET /api/products
- Get Product Details: GET /api/products/{productId}
- Create Product: POST /api/products/store
- Update Product: PUT /api/products/update/{productId}
- Partially Update Product: PATCH /api/products/update/partial/{productId}
- List Orders: GET /api/orders
- Create Order: POST /api/orders/store
- Get Order Details: GET /api/orders/details/{id}
{
"data": [
{
"id": 1,
"name": "T-shirt Blue",
"price": "$100.20",
"stock": 5
},
{
"id": 2,
"name": "T-shirt Green",
"price": "$200.00",
"stock": 10
}
],
"links": {
"first": "http://127.0.0.1:8000/api/products?page=1",
"last": "http://127.0.0.1:8000/api/products?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "http://127.0.0.1:8000/api/products?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"path": "http://127.0.0.1:8000/api/products",
"per_page": 10,
"to": 10,
"total": 10
}
}
{
"data": [
{
"order_id": 9,
"customer_name": "John Doe",
"total_amount": "600.40",
"order_items": [
{
"id": 9,
"product_id": 3,
"product_name": "T-shirt Blue",
"quantity": 2,
"sub_total": "200.40"
},
{
"id": 10,
"product_id": 4,
"product_name": "T-shirt Green",
"quantity": 2,
"sub_total": "400.00"
}
]
}
],
"links": {
"first": "http://127.0.0.1:8000/api/orders?page=1",
"last": "http://127.0.0.1:8000/api/orders?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "http://127.0.0.1:8000/api/orders?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"path": "http://127.0.0.1:8000/api/orders",
"per_page": 10,
"to": 1,
"total": 1
},
"total_order_amount": "600.40"
}