Download the PHP package caleb/laravel-practice without Composer
On this page you can find all versions of the php package caleb/laravel-practice. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download caleb/laravel-practice
More information about caleb/laravel-practice
Files in caleb/laravel-practice
Package laravel-practice
Short Description A Laravel practice development package, ready to use out of the box. It simplifies handling responses, filters, services, and exception management.
License MIT
Informations about the package laravel-practice
Laravel Practice
A Laravel practice development package, ready to use out of the box. It simplifies handling responses, filters, services, and exception management.
Features
- Standardized JSON Response: Unified API response format with request ID tracking
- Query Filters: Elegant and reusable query filtering system
- Service Layer: Base service class with exception handling capabilities
- Exception Management: Comprehensive exception handling with localized messages
- Model Standardization: Enhanced Eloquent models with standardized JSON serialization
- Request Context: Automatic request ID generation and context management
- Artisan Commands: Generate filters and services with custom commands
Requirements
- PHP ^8.1
- Laravel ^12.0
- ext-json
Installation
Install the package via Composer:
The package will automatically register its service provider.
Configuration
Publish Language Files
Publish Stubs
Usage
1. Response Trait
Use the Response trait in your controllers to standardize API responses:
Response format:
2. Query Filters
Create a filter class:
Define your filter:
Use in your model:
Apply filters in controller:
3. Service Layer
Create a service class:
Define your service:
Use in controller:
4. Model Standardization
Use the Standardization trait in your models:
Benefits:
- JSON serialization with
JSON_UNESCAPED_UNICODEflag - Dynamic
per_pagefrom request parameters - Built-in
filterscope for query filtering
5. Exception Handling
The package provides automatic exception handling with localized messages:
- ValidationException: Returns 422 with validation errors
- AuthenticationException: Returns 401 with error message
- PracticeException: Returns custom error code and message
- ModelNotFoundException: Returns 404 with "Resource not found" message
- ThrottleRequestsException: Returns 429 with rate limit message
Custom exceptions:
6. Request Context
The package automatically adds a unique request ID to each request context and includes it in all responses. This helps with request tracking and debugging.
Middleware
The package automatically registers the AddContext middleware which:
- Generates a unique UUID for each request
- Stores it in Laravel's Context
- Includes it in all JSON responses
Localization
The package supports multiple languages. Currently included:
English (en):
- System success/error messages
- Resource not found messages
Chinese (zh-CN):
- 系统成功/错误消息
- 资源未找到消息
You can publish and customize these messages:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.
Author
- Caleb - [email protected]
Keywords
- Laravel
- Response
- Request ID
- Service
- Filter
- Exception Handler
- Model Standardization
All versions of laravel-practice with dependencies
ext-json Version *