Skip to main content
This page provides a complete, copy-paste-ready CRUD example using the Rest Generic Class package. You’ll build a fully functional Product API with all CRUD operations.

Overview

We’ll create:
  • Model - Product model with relations
  • Service - Product service layer
  • Controller - RESTful API controller
  • Routes - API endpoint definitions
  • HTTP Examples - Complete request/response examples

Step 1: Create the Model

Create app/Models/Product.php:

Step 2: Create the Service

Create app/Services/ProductService.php:

Step 3: Create the Controller

Create app/Http/Controllers/Api/ProductController.php:

Step 4: Define Routes

Add to routes/api.php:

Step 5: Database Migration

Create the products table:

HTTP Request Examples

Create a Product

List Products with Filtering

Get Single Product

Update a Product

Delete a Product

Bulk Update Products

Advanced Filtering Examples

Search with Multiple Conditions

Testing Your API

1

Seed Test Data

Create a seeder to populate test products:
2

Test with cURL

3

Test with Postman

Import the API endpoints into Postman and test all CRUD operations with various filter combinations.
All endpoints automatically handle validation, error responses, and database exceptions. The BaseService provides built-in caching, filtering, and relation loading out of the box.
Remember to add all relations to the RELATIONS constant in your model. Unlisted relations will be rejected with a 400 error for security reasons.

Next Steps