gem-partij / gemboot-lara
Gemboot Lara - 支持SMVC开发方法的Laravel包
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.2
- irazasyed/telegram-bot-sdk: ^3.13
- laravel-notification-channels/telegram: ^5.0
- laravel/framework: ^11.0
Requires (Dev)
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^11.0.1
- dev-master
- 5.x-dev
- 5.2.0
- 5.1.1
- 5.1.0
- 5.0.1
- 5.0.0
- 4.x-dev
- 4.3.1
- 4.3.0
- 4.2.0
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.0
- 3.x-dev
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.x-dev
- 2.3.1
- 2.3.0
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 0.5.x-dev
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
This package is auto-updated.
Last update: 2024-09-08 03:49:10 UTC
README
支持SMVC开发方法的Laravel包
它做什么
安装gemboot包之前
use App\Models\User; class UserControllerApi extends Controller { // method to return all users public function index() { $status = 200; $message = 'Success!'; $data = []; try { // add user data to response $data = User::all(); } catch(\Exception $e) { // if catch error... // log error \Log::error($e->getMessage()); \Log::error($e->getTraceAsString()); // add error response $status = 500; $message = "Internal Server Error"; $data = [ 'error' => $e->getMessage(), ]; } // return response json return response()->json([ 'status' => $status, 'message' => $message, 'data' => $data, ], $status); } }
安装gemboot包之后
use GembootResponse; use App\Models\User; class UserControllerApi extends Controller { // method to return all users public function index() { return GembootResponse::responseSuccessOrException(function() { return User::all(); }); } }
将获得相同的响应
/* Success Response */ { "status": 200, "message": "Success!", "data": [ /* all user data... */ ] } /* Error Response */ { "status": 500, /* it could be 400 to 500 error status code */ "message": "Error!", "data": [ /* all error data... */ ] }
文档、安装和使用说明
有关详细的安装和使用说明,请参阅文档。
支持策略
只有最新版本会获得新功能。
安装
在您的composer.json
中要求gem-partij/gemboot-lara
包,并更新您的依赖项
composer require gem-partij/gemboot-lara
可选:服务提供程序将自动注册。或者,您可以在config/app.php文件中手动添加服务提供程序
'providers' => [ // ... \Gemboot\GembootServiceProvider::class, ];
可选:别名将自动注册。或者,您可以在config/app.php文件中手动添加gemboot别名
'aliases' => [ // ... 'GembootBadRequestException' => Gemboot\Exceptions\BadRequestException::class, 'GembootForbiddenException' => Gemboot\Exceptions\ForbiddenException::class, 'GembootNotFoundException' => Gemboot\Exceptions\NotFoundException::class, 'GembootServerErrorException' => Gemboot\Exceptions\ServerErrorException::class, 'GembootUnauthorizedException' => Gemboot\Exceptions\UnauthorizedException::class, 'GembootRequest' => Gemboot\Facades\GembootRequestFacade::class, 'GembootResponse' => Gemboot\Facades\GembootResponseFacade::class, 'GembootController' => Gemboot\Controllers\CoreRestController::class, 'GembootProxyController' => Gemboot\Controllers\CoreRestProxyController::class, 'GembootResourceController' => Gemboot\Controllers\CoreRestResourceController::class, 'GembootModel' => Gemboot\Models\CoreModel::class, 'GembootService' => Gemboot\Services\CoreService::class, ];
Gemboot网关(附加包)
中间件
要使用Gemboot网关的所有路由,请在app/Http/Kernel.php
类中$middleware
属性中添加CheckToken
中间件
protected $middleware = [ // ... \Gemboot\Gateway\Middleware\CheckToken::class, ];
配置
默认值在config/gemboot_gw.php
中设置。发布配置以将文件复制到您自己的配置
php artisan vendor:publish --tag="gemboot-gateway"
Gemboot身份验证(附加包)
中间件
要为您的路由使用Gemboot身份验证中间件,请将TokenValidated
、HasRole
、HasPermissionTo
中间件添加到app/Http/Kernel.php
类中的$routeMiddleware
属性
protected $routeMiddleware = [ // ... 'token-validated' => \Gemboot\Middleware\TokenValidated::class, 'role' => \Gemboot\Middleware\HasRole::class, 'permission' => \Gemboot\Middleware\HasPermissionTo::class, ];
配置
默认值在config/gemboot_auth.php
中设置。发布配置以将文件复制到您自己的配置
php artisan vendor:publish --tag="gemboot-auth"
路由
如果需要使用它,请在您的路由中添加Gemboot AuthLibrary,例如
use Illuminate\Http\Request; use Gemboot\Libraries\AuthLibrary; Route::middleware('api')->prefix('auth')->group(function() { Route::post('login', function(Request $request) { return (new AuthLibrary)->login($request->npp, $request->password, true); }); Route::get('me', function() { return (new AuthLibrary)->me(true); }); Route::get('validate-token', function() { return (new AuthLibrary)->validateToken(true); }); Route::get('has-role', function(Request $request) { return (new AuthLibrary)->hasRole($request->role_name, true); }); Route::get('has-permission-to', function(Request $request) { return (new AuthLibrary)->hasPermissionTo($request->permission_name, true); }); Route::post('logout', function() { return (new AuthLibrary)->logout(true); }); });
Gemboot文件处理器(附加包)
配置
默认值在config/gemboot_file_handler.php
中设置。发布配置以将文件复制到您自己的配置
php artisan vendor:publish --tag="gemboot-file-handler"
文件处理器使用
现在您可以使用gemboot文件处理器上传图片或文档。
use Illuminate\Http\Request; use Gemboot\FileHandler\FileHandler; class ExampleController extends Controller { public function uploadImage(Request $request) { $image = $request->file_image; $new_filename = "Gambar.jpeg"; $save_path = "/gambar/2020"; return (new FileHandler($image)) ->uploadImage($new_filename, $save_path) ->object(); } }
uploadImage、uploadDocument方法返回一个Illuminate\Http\Client\Response实例,该实例提供多种可能用于检查响应的方法
$response->body() : string; $response->json($key = null) : array|mixed; $response->object() : object; $response->collect($key = null) : Illuminate\Support\Collection; $response->status() : int; $response->ok() : bool; $response->successful() : bool; $response->redirect(): bool; $response->failed() : bool; $response->serverError() : bool; $response->clientError() : bool; $response->header($header) : string; $response->headers() : array;
更多信息:https://laravel.net.cn/docs/9.x/http-client#making-requests
测试
使用以下命令运行测试
composer test
贡献
有关详细信息,请参阅CONTRIBUTING。
安全
如果您发现任何安全问题,请通过电子邮件anggerpputro@gmail.com报告,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。