定制 larapi/zkrcrud 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

larapi/zkrcrud

最新稳定版本:v1.0.0

Composer 安装命令:

composer require larapi/zkrcrud

包简介

A Laravel package to simplify the creation of RESTful APIs, similar to Orion.

README 文档

README

Laravel PHP License

ZKRCrud is a powerful Laravel package that automates RESTful API development with built-in CRUD operations, advanced filtering, and policy-based authorization. Perfect for rapid API development with Laravel 10+.

✨ Key Features

  • 🚀 Auto-generated CRUD endpoints
  • 🔒 Policy-based authorization
  • 🔍 Advanced query filtering (Spatie Query Builder)
  • Automatic request validation
  • 📊 Smart pagination
  • 🛡️ Comprehensive error handling
  • 🔄 Pre/post operation hooks

📦 Installation

Install via Composer:

composer require larapi/zkrcrud

🚀 Quick Start
1. Create Controller
<?php 
namespace App\Http\Controllers;

use Larapi\Zkrcrud\Http\Controllers\ZkrController;
use App\Models\Product;

class ProductController extends ZkrController
{
    protected $model = Product::class;
    
    protected $allowedIncludes = ['category', 'reviews'];
    protected $allowedFilters = ['name', 'price', 'in_stock'];
    protected $allowedSorts = ['created_at', 'price'];
    protected $allowedFields = ['id', 'name', 'price'];
    
    protected function rules(): array
    {
        return [
            'name' => 'required|string|max:100',
            'price' => 'required|numeric|min:0',
        ];
    }
}
  1. Define Routes
<?php
use App\Http\Controllers\ProductController;

Route::apiResource('products', ProductController::class);

2. Define Routes

use App\Http\Controllers\ProductController;

Route::apiResource('products', ProductController::class);

🔍 API Endpoints

Method | Endpoint | Description GET | /products | Paginated product list GET | /products/{id} | Get single product POST | /products | Create new product PUT | /products/{id} | Update product DELETE | /products/{id} | Delete product

⚙️ Advanced Usage

Query Filtering

GET /products?filter[price][gt]=100&include=category&sort=-created_at

Supported Parameters:

include – Load relationships

filter – Filter by fields

sort – Sort results (- prefix for DESC)

fields – Select specific fields

per_page – Items per page (pagination)

🛠️ Custom Hooks Example usage of hooks inside the controller:

protected function beforeStore(Request $request)
{
    // Logic before creation
    $request->merge(['created_by' => auth()->id()]);
}

protected function afterUpdate($model, Request $request)
{
    // Logic after update
    $model->history()->create($request->all());
}

🔒 Authorization Automatically checks the following policy methods:

Action Policy Method List viewAny View view Create create Update update Delete delete

🛠️ Configuration Required:

<?php
class YourController extends Controller{
protected $model = YourModel::class;
protected ?string $requestClass = CustomRequest::class;
protected array $allowedIncludes = [];
protected array $allowedFilters = [];
protected array $allowedSorts = [];
protected array $allowedFields = [];
/// rest of the code
}

Optional:

protected ?string $requestClass = CustomRequest::class;
protected array $allowedIncludes = [];
protected array $allowedFilters = [];
protected array $allowedSorts = [];
protected array $allowedFields = [];

🛠️ System Requirements PHP 8.1+

Laravel 10+

Composer 2.0+

🤝 Contributing Pull requests are welcome! Please follow PSR-12 coding standards.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via taylor@laravel.com. All security vulnerabilities will be promptly addressed.

License

The Laravel framework is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固