Download the PHP package ibekzod/microcrud without Composer
On this page you can find all versions of the php package ibekzod/microcrud. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package microcrud
MicroCRUD
MicroCRUD is a comprehensive Laravel package that eliminates boilerplate code and accelerates API development. Build production-ready RESTful APIs in minutes with advanced features like type-aware filtering, intelligent caching, queue support, and automatic validation.
Why MicroCRUD?
Stop writing the same CRUD logic over and over. MicroCRUD provides:
- ⚡ Rapid Development - Create full CRUD APIs with just 3 classes
- 🎯 Type-Aware Filtering - Automatic search filters based on database column types
- 🔍 Advanced Querying - Range filters, dynamic sorting, grouping, soft deletes, pagination
- 📊 Dynamic Grouping - Group by model columns or relations with auto-joins and eager loading
- ✅ Auto Validation - Generate validation rules from database schema
- 💾 Smart Caching - Tag-based cache with automatic invalidation
- 🚀 Queue Support - Background processing for heavy operations
- 🌐 Multi-Database - MySQL, PostgreSQL, SQLite, SQL Server
- 🌍 i18n Ready - Multi-language support out of the box
- 📦 Bulk Operations - Process multiple records efficiently
- 🎨 Highly Extensible - Hooks, events, and customization points
Table of Contents
- Requirements
- Installation
- Quick Start
- Architecture
- Core Concepts
- Features
- Dynamic Filtering
- Validation System
- Caching
- Queue Jobs
- Bulk Operations
- Soft Deletes
- Hooks & Events
- API Documentation
- Advanced Usage
- Middleware
- Configuration
- Examples
- Testing
- Contributing
- Changelog
- License
Requirements
| Requirement | Version |
|---|---|
| PHP | ^7.0 | ^8.0 | ^8.1 | ^8.2 | ^8.3 |
| Laravel | 5.2 - 12.x |
Installation
Install the package via Composer:
The package will automatically register itself via Laravel's package discovery.
Publish Assets (Optional)
Publish configuration files and translations:
This will create:
config/microcrud.php- Package configurationconfig/schema.php- Multi-schema database configuration (PostgreSQL)lang/vendor/microcrud/- Translation files (en, ru, uz)
Quick Start
Create a complete CRUD API in 3 steps:
Step 1: Create Your Model
Step 2: Create Your Service
Step 3: Create Your Controller
Step 4: Register Routes
Option 1: Use Route Macros (Recommended - all POST endpoints):
This creates 7 POST endpoints:
POST /products/create→ create()POST /products/update→ update()POST /products/show→ show()POST /products/index→ index()POST /products/delete→ delete()POST /products/restore→ restore()POST /products/bulk-action→ bulkAction()
Option 2: RESTful Routes (Standard Laravel):
That's it! You now have a fully functional API with:
- ✅ List with pagination and filtering
- ✅ Create with validation
- ✅ Read single item
- ✅ Update with validation
- ✅ Delete (soft/hard)
- ✅ Restore soft-deleted items
- ✅ Bulk operations
Architecture
MicroCRUD follows the Service-Repository-Controller pattern with a focus on separation of concerns:
Component Breakdown
| Component | Purpose | File Location |
|---|---|---|
| Model | Eloquent ORM models | Microcrud\Abstracts\Model |
| Service | Business logic & operations | Microcrud\Abstracts\Service |
| Controller | HTTP handling & routing | Microcrud\Http\CrudController |
| Resource | API response transformation | Microcrud\Responses\ItemResource |
| Middleware | Request preprocessing | Microcrud\Middlewares\* |
| Jobs | Background processing | Microcrud\Abstracts\Jobs\* |
| Exceptions | Error handling | Microcrud\Abstracts\Exceptions\* |
Core Concepts
Services
Services contain all business logic. The base Service class provides:
Controllers
Controllers handle HTTP requests and delegate to services:
Resources
Resources transform model data for API responses:
Route Macros
MicroCRUD provides convenient Route macros for registering CRUD resources:
With Middleware & Prefix:
Benefits:
- ✅ 75% less code than manual route definitions
- ✅ Consistent pattern across all resources
- ✅ Works with middleware, prefixes, and versioning
- ✅ All POST endpoints (production-tested pattern)
Features
Dynamic Filtering
MicroCRUD automatically detects column types and provides intelligent filtering:
String Columns → LIKE Search
Numeric Columns → Exact Match + Range
Date Columns → Exact Match + Range
Boolean Columns → Exact Match
Dynamic Sorting
Dynamic Grouping
Group results by model columns or relation columns:
Simple Grouping:
Grouped Pagination (Top N per Group):
Mixed Syntax (Simple + Configured):
Features:
- ✅ Simple GROUP BY - For aggregations and unique value queries
- ✅ Top N per Group - Get first/last/top N records per group using window functions
- ✅ Hierarchical Responses - Nested parent-child structure with
hierarchical: true - ✅ Relation Support - Group by relation columns (e.g.,
block.manager_id) - ✅ Auto JOIN & Eager Load - Automatically joins and eager loads relations
- ✅ Search within Groups - Filter specific groups with search parameter
- ✅ Nested Relations - Supports multi-level relations (e.g.,
block.manager.department_id) - ✅ Relation Exclusion - Prevent duplicate data with
exclude_relationsparameter - ✅ Validates Everything - Checks columns and relations exist
- ✅ Database Agnostic - Works with MySQL 8+, PostgreSQL, SQL Server
Response Structure:
The response format depends on whether hierarchical is enabled:
1. Flat Grouped Response (hierarchical: false or not set)
Basic (returns first record per group - non-deterministic):
With Aggregate Selection (deterministic):
Method 1: Top-level parameters
Method 2: Inline syntax (recommended)
Both return newest apartment per object
Or use group_aggregate shortcuts:
first: First record (ORDER BY column ASC, get first)last: Last record (ORDER BY column DESC, get first)max: Max value (ORDER BY column DESC, get first)min: Min value (ORDER BY column ASC, get first)
Response (flat list with standard pagination):
2. Hierarchical Grouped Response (hierarchical: true)
Basic example:
With aggregations and inline ordering:
Returns nested structure (group → children):
Comparison Table:
| Feature | Flat (hierarchical: false) | Hierarchical (hierarchical: true) |
|---|---|---|
| Structure | [{...}, {...}] |
[{group: {...}, data: [...]}, ...] |
| Parent Data | Repeated in each record | Once per group |
| Records per Group | 1 (configurable with group_aggregate) |
ALL |
| Pagination | Paginates individual records | Paginates groups |
| Relations | Included (normal behavior) | Auto-excluded from children |
| Aggregate Selection | ✅ group_aggregate, group_order_by |
N/A |
| Use Case | Standard listing, latest/oldest per group | Parent-child navigation |
| Performance | Good for simple lists | Better for complex hierarchies |
3. With Aggregation - Add selectRaw() in beforeIndex() for COUNT/SUM/AVG/MAX/MIN
4. Top N per Group - Use window functions (see Performance Guide)
5. With Relations - Automatically eager loads relations (no N+1)
Example Response (with aggregation):
Example Model Setup:
Pagination
Combining Filters
Validation System
Validation rules are auto-generated from your database schema:
Auto-Generated Rules Based on Column Types:
string→sometimes|nullableinteger→sometimes|integernumeric→sometimes|numericdate→sometimes|dateboolean→sometimes|boolean
Plus automatic range validation:
- Integer:
search_by_{column}_min,search_by_{column}_max - Date:
search_by_{column}_from,search_by_{column}_to
Caching
Enable intelligent caching with automatic invalidation:
Manual cache control:
Queue Jobs
Process heavy operations in the background:
Available Jobs:
StoreJob- Background creationUpdateJob- Background updatesDeleteJob- Background deletion
Job Features:
- ✅
ShouldQueue- Async processing - ✅
ShouldBeUnique- Prevent duplicates - ✅ Failed job logging
- ✅ Configurable queue names
Bulk Operations
Process multiple records efficiently:
Bulk Features:
- Transaction support (all or nothing)
- Queue support for large batches
- Validation for each item
- Progress tracking
Soft Deletes
Full soft delete support with easy restoration:
Hooks & Events
Add custom logic at any point in the lifecycle:
Available Hooks:
beforeCreate($data)afterCreate($item)beforeUpdate($id, $data)afterUpdate($item)beforeDelete($id)afterDelete($item)beforeRestore($id)afterRestore($item)afterIndex()
API Documentation
Standard Response Format
Success Response (Single Item)
Success Response (Paginated List)
Error Response (Validation)
Error Response (Not Found)
HTTP Status Codes
| Method | Endpoint | Success Status | Description |
|---|---|---|---|
| GET | /products |
200 OK | List products |
| GET | /products/{id} |
200 OK | Get single product |
| POST | /products |
201 Created | Create product |
| PUT | /products/{id} |
202 Accepted | Update product |
| DELETE | /products/{id} |
202 Accepted | Delete product |
| POST | /products/{id}/restore |
202 Accepted | Restore product |
| POST | /products/bulk |
202 Accepted | Bulk operation |
Error Status Codes
| Status Code | Method | Description |
|---|---|---|
| 400 | errorBadRequest() |
Bad Request |
| 401 | errorUnauthorized() |
Unauthorized |
| 403 | errorForbidden() |
Forbidden |
| 404 | errorNotFound() |
Not Found |
| 422 | errorValidation() |
Validation Error |
| 500 | error() |
Internal Server Error |
Advanced Usage
Custom Resources
Create custom transformations for your API responses:
Use in controller:
Transaction Management
Transactions are enabled by default. Control them per service:
Custom Query Scopes
Add custom query modifications:
Preventing N+1 Queries
Eager load relationships to prevent N+1 queries:
Without Global Scopes
Remove global scopes temporarily:
Parent-Child Relationships
For hierarchical data like categories or organizational structures:
Usage:
Auto-cascade delete:
HTTP Client Service
Make external API calls with the built-in HTTP client:
Middleware
LocaleMiddleware
Automatically sets application locale from Accept-Language header:
Request:
Behavior:
- Checks
Accept-Languageheader - Matches against configured locales (
config('microcrud.locales')) - Falls back to
config('microcrud.locale')
TimezoneMiddleware
Sets timezone from Timezone header:
Request:
Default: Uses config('microcrud.timezone', 'UTC')
LogHttpRequest
Logs all HTTP requests with URL, headers, and parameters:
Logs to Laravel's default log channel.
Configuration
config/microcrud.php
config/schema.php
For PostgreSQL multi-schema support:
Environment Variables
Add to your .env:
Examples
Complete E-commerce Product API
API Usage Examples
Testing
While the package doesn't include a test suite, here's how to test your implementations:
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
Coding Standards
- Follow PSR-12 coding standards
- Write descriptive commit messages
- Add tests for new features
- Update documentation
Changelog
[Latest] - 2025-01-30
Added
- ✨ Dynamic Grouping (group_bies) - Group results by model columns or relations with auto-joins and eager loading
- ✨ Grouped Pagination - "Top N per Group" queries using window functions (ROW_NUMBER OVER PARTITION BY)
- ✨ Hierarchical Grouped Responses - Nested parent-child structure with pagination at each level (
hierarchical: true) - ✨ Relation Exclusion - Prevent duplicate relation data in leaf resources (
exclude_relationsparameter) - ✨ Group Aggregations - Calculate COUNT/SUM/AVG/MAX/MIN per group level
- ✨ Route Macros -
Route::microcrud()andRoute::microcruds()for easy resource registration - ✨ Enhanced Exceptions - Rich error context with toArray()/toJson() methods
- ✨ Improved Middlewares - Better security, logging, and validation
- 📚 Comprehensive Documentation - Enhanced code documentation throughout
Improved
- ⚡ Better Error Handling - ValidationException, CreateException, UpdateException, DeleteException, NotFoundException
- 📝 Controller Documentation - Full PHPDoc for all methods
- 🎨 Code Quality - Better structure, logging, and maintainability
- 🔒 Security - Sensitive data filtering in LogHttpRequest middleware
Previous Releases
- Type-aware dynamic search filters - min/max for numeric, from/to for dates
- DeleteJob - Background deletion operations
- Configurable timezone - Via
config('microcrud.timezone') - DYNAMIC search_by_column & order_by_column - Added dynamic filtering
- Bulk actions - Implemented bulk operations
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Credits
- Author: iBekzod
- Email: [email protected]
- Package: ibekzod/microcrud
License
The MIT License (MIT). Please see License File for more information.
Made with ❤️ by iBekzod
All versions of microcrud with dependencies
illuminate/database Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/filesystem Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/http Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0