Download the PHP package rizkussef/laravel-crud-api without Composer
On this page you can find all versions of the php package rizkussef/laravel-crud-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rizkussef/laravel-crud-api
More information about rizkussef/laravel-crud-api
Files in rizkussef/laravel-crud-api
Package laravel-crud-api
Short Description A clean, scalable Api CRUD package for the Service-based architecture for Laravel with advanced filtering, eager-loading relationships, and automatic resource resolution
License MIT
Homepage https://github.com/rizkussef/laravel-crud-api
Informations about the package laravel-crud-api
🚀 Laravel CRUD Api Package
[](https://packagist.org/packages/rizkussef/laravel-crud-api) [](https://packagist.org/packages/rizkussef/laravel-crud-api) [](LICENSE)
A clean, scalable Api CRUD architecture for Laravel, built around a reusable Base Service and Base Controller with automatic:
- ✅ Model Resolution
- ✅ Resource Resolution
- ✅ Collection Handling
- ✅ Pagination
- ✅ Advanced Filtering (=, !=, >, <, >=, <=, LIKE, IN, BETWEEN, NULL checks, Date operations)
- ✅ Eager Loading Relationships
- ✅ API Response Formatting
- ✅ Auto-Validation using Form Requests
- ✅ Auto Creation of Model, Resource, Requests, Controller, Service, Migration using Command
Designed to eliminate repetitive CRUD logic while keeping your application clean and maintainable. Pass filters and relationships directly from your frontend to dynamically build optimized queries with full control over data retrieval.
📦 Installation
Install via Composer:
If needed, manually register the provider in:
⚙️ Publish Configuration
This will publish:
Example:
🏗 Architecture
⚡ Artisan Generator Command
The absolute fastest way to get started is by using the built-in Artisan generator. This powerful command scaffolds a fully functional CRUD API endpoint in seconds!
🎯 Example: Creating an Article API
What happens behind the scenes? The command automatically generates all layers required for an API CRUD operation:
| Layer | Generated File | Description |
|---|---|---|
| Model | App\Models\Article.php |
The Eloquent model (along with its database migration). |
| Resource | App\Http\Resources\ArticleResource.php |
Automatically serializes and formats your JSON response. |
| Requests | App\Http\Requests\ArticleRequest.phpArticleUpdateRequest.php |
Dedicated Form validation classes (Auto-validated by Controller). |
| Service | App\Services\ArticleService.php |
Core business logic layer (Extends ApiCrudService). |
| Controller | App\Http\Controllers\ArticleController.php |
Handles routing and formatting (Extends ApiCrudController). |
⚙️ Available Options
| Option | Description | Example |
|---|---|---|
--no-migration |
Tells the generator to skip database migration file creation. | php artisan api-crud:make User --no-migration |
Once generated, just register your new endpoint in routes/api.php and you're fully operational!
🛠 Manual Setup (Step-by-Step)
1️⃣ Create a Service
🔎 Automatic Resolution (Models, Resources, and Form Requests)
The architecture heavily relies on naming conventions to automatically resolve dependencies:
No need to manually inject or define the Model, Resource, or Form Requests. ApiCrudController automatically validates inbound requests using the resolved Form Request before passing data to the Service.
2️⃣ Create a Controller
Just Inject the specific service for this controller.
� Filters & Relationships
The package includes powerful filtering and eager-loading capabilities. Pass filters and relationships from the frontend to dynamically build queries. They can be passed either as array parameters or as JSON-encoded strings.
Available Filter Operators
Comparison Operators
String Matching
Array Operations
NULL Checks
Date Operations
Frontend Examples
Axios Example
Backend Services Examples
Another Service Calling This Service
�🔁 Built-in CRUD Methods
The BaseCrudController provides:
index()– List recordsgetPaginated($perPage)- Paginate list of recordsshow($id)– Show single recordstore(Request $request)– Automatically resolves and validates the incoming Request using the associated Form Request, then creates recordupdate(Request $request, $id)– Automatically resolves and validates using the associated Update Form Request, then updates recorddestroy($id)– Delete record
Controller handles validation & response formatting. All business logic is handled inside ApiCrudService.
📄 Automatic Resource Handling
Single Item
Collection
Automatically handled by the base service.
No Resource
If the corresponding Resource class does not exist, the base controller will return the raw model data instead of a resource.
📊 Example JSON Response
GET /users
🧠 Best Practices
✔ Use the Artisan Generator Command to create all layers automatically.
✔ Keep business logic inside Model-specific services.
✔ Keep controllers thin.
✔ Extend ApiCrudService instead of modifying it.
✔ Use Resources for API formatting.
✔ Use filters and relationships to avoid N+1 query problems.
Example 1: Simple Business Logic with Filters
Example 2: Complex Filtering with Date Range
Example 3: Filtering with NULL Checks
🔌 Dependency Injection
ApiCrudService is bound in the container via the Service Provider, so it can be injected anywhere.
🔧 Extending
You can extend:
- ApiCrudController
- ApiCrudService
- Pagination configuration
And you can use:
- API Response Trait
- Filter Query Trait
- Relationship Query Trait
🛣 Example Routes
👨💻 Author & Support
Developed by Rizk Ussef
A fullstack developer passionate about creating clean, maintainable architecture patterns and reusable solutions for building scalable applications across frontend and backend ecosystems.
Get in Touch
- GitHub: @rizkussef
- Email: [email protected]
- Issues & Feedback: GitHub Issues
🤝 Contributing
Contributions are welcome! If you find bugs or have feature suggestions, please open an issue or submit a pull request.
📄 License
MIT License - see LICENSE file for details.