khazhinov / laravel-lighty
一套快速创建CRUD REST API的工具
11.0.7
2024-03-18 17:47 UTC
Requires
- php: ^8.1
- ext-exif: *
- ext-fileinfo: *
- ext-json: *
- ext-sodium: *
- illuminate/bus: ^10.0
- illuminate/config: ^10.0
- illuminate/console: ^10.0
- illuminate/database: ^10.0
- illuminate/http: ^10.0
- illuminate/pipeline: ^10.0
- illuminate/support: ^10.0
- khazhinov/laravel-fly-docs: ^10.0
- khazhinov/php-support: ^1.0
- maatwebsite/excel: ^3.1
- psr/simple-cache: ^1.0
- spatie/data-transfer-object: ^3.8
- symfony/console: ^6.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.11
- laravel/framework: ^10.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-symfony: ^1.2
- dev-main
- 11.0.7
- 11.0.6
- 11.0.5
- 11.0.4
- 11.0.3
- 11.0.2
- 11.0.1
- 11.0.0
- 10.0.2
- 10.0.1
- 10.0.0
- 9.13
- 9.12
- 9.11
- 9.10
- 9.9
- 9.8
- 9.7
- 9.6
- 9.5
- 9.4
- 9.3
- 9.2
- 9.1
- 1.9.7
- 1.9.6
- 1.9.5
- 1.9.4
- 1.9.3
- 1.9.2
- 1.9.1
- 1.9
- 1.8.5
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8
- 1.7.18
- 1.7.17
- 1.7.16
- 1.7.15
- 1.7.14
- 1.7.13
- 1.7.12
- 1.7.11
- 1.7.10
- 1.7.9
- 1.7.8
- 1.7.7
- 1.7.6
- 1.7.5
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.10
- 1.6.9
- 1.6.8
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6
- 1.5
- 1.4
- 1.3
- 1.2
- 1.1
- 1.0
This package is auto-updated.
Last update: 2024-09-18 18:56:39 UTC
README
Laravel Lighty ⚡️
一套用于快速创建CRUD REST API的工具
描述
该库提供了一套工具,用于快速创建执行基本CRUD操作的REST API。
安装
安装此库需要使用Composer(Laravel 9+)
composer require "khazhinov/laravel-lighty:^9.0"
如有需要,请发布配置文件
php artisan vendor:publish --provider="Khazhinov\LaravelLighty\LaravelLightyServiceProvider" --tag="config"
以及XSLX导出模板
php artisan vendor:publish --provider="Khazhinov\LaravelLighty\LaravelLightyServiceProvider" --tag="views"
错误处理器
库提供了一个基本的错误处理器类,该类将根据接受的格式化结构对服务器响应进行格式化。
要实现错误处理器,请从Khazhinov\LaravelLighty\Exceptions\ExceptionHandler
继承App\Exceptions\Handler
类(app/Exception/Handler.php)
namespace App\Exceptions; use Khazhinov\LaravelLighty\Exceptions\ExceptionHandler; use Throwable; class Handler extends ExceptionHandler { /** * A list of the exception types that are not reported. * * @var array<int, class-string<Throwable>> */ protected $dontReport = [ // ]; /** * A list of the inputs that are never flashed for validation exceptions. * * @var array<int, string> */ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; }
使用
该库提供了一套Artisan命令,用于快速生成创建REST API所需的所有类。
简单使用
php artisan lighty:generator TestEntity v1.0 --migration
执行此命令后,将生成以下文件结构
终端还将输出添加到路由器所需的信息
#/api/v1.0/testEntities Route::group([ "namespace" => "TestEntity", "prefix" => "/testEntities", "as" => "test_entities.", ], static function () { Route::get("/validations/{method?}", "TestEntityCRUDController@getValidations")->name("validations"); Route::get("/", "TestEntityCRUDController@index")->name("index"); Route::post("/search", "TestEntityCRUDController@index")->name("search"); Route::post("/setPosition", "TestEntityCRUDController@setPosition")->name("set-position"); Route::post("/", "TestEntityCRUDController@store")->name("store"); Route::delete("/", "TestEntityCRUDController@bulkDestroy")->name("bulk-destroy"); #/api/v1.0/testEntities/:key Route::group([ "prefix" => "/{key}", ], static function () { Route::get("/", "TestEntityCRUDController@show")->name("show"); Route::put("/", "TestEntityCRUDController@update")->name("update"); Route::delete("/", "TestEntityCRUDController@destroy")->name("destroy"); }); });
API路由器示例(routes/api.php)
<?php use Illuminate\Support\Facades\Route; # /api/v1.0/ Route::group(["namespace" => "App\Http\Controllers\Api\V1_0", "prefix" => "/v1.0", "as" => "api.v1_0"], static function () { #/api/v1.0/testEntities Route::group([ "namespace" => "TestEntity", "prefix" => "/testEntities", "as" => "test_entities.", ], static function () { Route::get("/validations/{method?}", "TestEntityCRUDController@getValidations")->name("validations"); Route::get("/", "TestEntityCRUDController@index")->name("index"); Route::post("/search", "TestEntityCRUDController@index")->name("search"); Route::post("/setPosition", "TestEntityCRUDController@setPosition")->name("set-position"); Route::post("/", "TestEntityCRUDController@store")->name("store"); Route::delete("/", "TestEntityCRUDController@bulkDestroy")->name("bulk-destroy"); #/api/v1.0/testEntities/:key Route::group([ "prefix" => "/{key}", ], static function () { Route::get("/", "TestEntityCRUDController@show")->name("show"); Route::put("/", "TestEntityCRUDController@update")->name("update"); Route::delete("/", "TestEntityCRUDController@destroy")->name("destroy"); }); }); });
许可证
MIT许可证。有关更多信息,请参阅许可证文本。