The Laravel framework is open-sourced software licensed under the MIT license.
- Clone repo and install dependencies
git clone https://github.com/yourusername/school-uniform-api.git
cd school-uniform-api
composer install
cp .env.example .env
php artisan key:generate
- Setup database in .env and run migrations
php artisan migrate
- Database & Models
Create Students, Uniforms, Orders tables via migrations
Models: Student.php, Uniform.php, Order.php
Setup relationships:
Student hasMany Orders
Uniform hasMany Orders
Order belongsTo Student & Uniform
5.Controllers & Routes
php artisan make:controller StudentController --api
php artisan make:controller UniformController --api
php artisan make:controller OrderController --api
-
Define API routes in routes/api.php using Route::apiResource()
-
Order Logic
In OrderController@store, validate request and calculate total price
Save order with student_id, uniform_id, quantity, total_price
Return created order JSON response
- Testing with Postman





Aage kya karein? (Advanced / Real Use Features)
Here are 3 options — tum decide karo:
1. Upload Uniform Images (File Upload Feature)
Uniforms ke saath image bhi dikhana ho toh.
Add image column to uniforms table
Store files via Laravel’s Storage system
API accepts file via Postman (or frontend)
2. Filter/Search APIs
E.g., GET /api/uniforms?size=M, ya orders by student
Query parameters use karke search karna
Filter by size, color, student_id, etc.
3. Dashboard-style Stats API
Simple analytics ke liye
Total orders
Revenue = sum of all total_price
Top-selling uniform
Orders per student
Can return via:
bash
Copy
Edit
GET /api/stats
public function index(Request $request)
{
$query = Uniform::query();
if ($request->has('size')) {
$query->where('size', $request->size);
}
if ($request->has('color')) {
$query->where('color', $request->color);
}
return $query->get();
}

public function index(Request $request)
{
$query = Order::with(['student', 'uniform']);
if ($request->has('student_id')) {
$query->where('student_id', $request->student_id);
}
return $query->get();
}

5. Test in Postman
Change method to POST
URL: http://127.0.0.1:8000/api/uniforms
Body → form-data
name: Shirt
price: 499
size: M
color: White
image: select a file (type = File)
🔚 Response
It will return the image path:
json
Copy
Edit
{
"id": 1,
"name": "Shirt",
"image": "uniforms/shirt.jpg",
...
}
You can display it via:
php-template
Copy
Edit
<img src="http://127.0.0.1:8000/storage/uniforms/shirt.jpg" />
✅ Done bro! Now uniform images bhi save ho rahe hain.
Bolo — edit/update image feature bhi chahiye? Ya aage badhein to dashboard stats?