tomatophp/laravel-tomato
Composer 安装命令:
composer require tomatophp/laravel-tomato
包简介
Basic Laravel Helpers for requests and controllers build by TomatoPHP
README 文档
README
Laravel Tomato
Basic Laravel Helpers for requests and controllers build by TomatoPHP
Installation
composer require tomatophp/laravel-tomato
Features
-
Tomato::menu()inject and handle menus across your application -
Tomato::widget()inject and handle widgets across your application -
Tomato::slot()inject and handle slots across your application -
Tomato::request()handle and validate requests -
Tomato::response()handle api responses
Usage
you can use the helper by Facade class or by using the helper function
use TomatoPHP\LaravelTomato\Facades\Tomato::register();
or just
tomato()::register();
Register Components
you can register your menu, widget, or slot in your service provider boot() method
Tomato::register([ Menu::make() ->group(__('CRM')) ->label(__('Name')) ->route('home') ->icon('home'), Widget::make() ->group(__('CRM')) ->label(__('Name')) ->counter(100) ->icon("bx bx-user"), Slot::make() ->position(Positions::dashboardTop) ->view('dashboard-top'), ]);
you can register any type of component and we will check it and handle it for you
all components have a macroable methods to add more functionality to it.
Get Components
you can get your components like this
Tomato::menu()->get(); Tomato::widget()->get(); Tomato::slot()->get();
it will return an array of registered components for you
Request
you can use the request helper to handle and validate your requests like this
return Tomato::request()->index( request: request(), model: App\Models\User::class, );
🔁 Index Request
this method returns view or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
requestthe request objectmodelthe model you want to getviewthe view you want to returntablethe table class you want to usedatathe data you want to pass to the viewapiif you want to return JsonResponse or notresourceresource class to resource your returned dataqueryif you want to add some query to the modelfiltersif you want to add some filters to the table
public function index(Request $request): View|JsonResponse { return Tomato::index( request: $request, //Required model: $this->model, //Required view: 'users.index', table: \App\Tables\UserTable::class, data: [ 'name' => 'john doe', ], api: true, resource: UserResource::class, query: User::query()->where('is_activated',true), filters: [ 'is_activated', ], ); }
🔁 JSON Request
this method return only json response of the model to make it easy to access it with x-splade-select or x-tomato-admin-select
this method accept some arguments:
requestthe request objectmodelthe model you want to getdatathe data you want to pass to the viewpaginateif you want to paginate the response or notqueryif you want to add some query to the modelfiltersif you want to add some filters to the table
public function api(Request $request): JsonResponse { return Tomato::json( request: $request, //Required model: \App\Models\User::class, //Required data: [ 'name' => 'john doe', ], paginate: 10, query: User::query()->where('is_activated',true), filters: [ 'is_activated', ], ); }
🔁 Get Request
this method returns view or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
modelthe model you want to getviewthe view you want to returndatathe data you want to pass to the viewhasMediaif you want to get the media of the model or notcollection [array]the media collection you want to get as array take true if it's multi or false if it's singleattach [array]to attach some data to the modelapiif you want to return JsonResponse or notresourceresource class to resource your returned dataqueryif you want to add some query to the model
public function show(\App\Models\User $model): View|JsonResponse { return Tomato::get( model: $model, //Required view: 'users.show', //Required data: [ 'name' => 'john doe', ], hasMedia: true, collection: [ 'avatar' => false, 'gallery' => true ], attach: [ 'roles' => $model->roles, ], api: true, resource: UserResource::class, query: User::query()->where('is_activated',true) ); }
🔁 Store Request
this method returns RedirectResponse or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
requestthe request objectmodelthe model you want to getvalidationthe validation rules you want to usemessagethe message you want to return with the responsevalidationErrorthe message you want to return if the validation failedredirectthe redirect route you want to redirect tohasMediaif you want to get the media of the model or notcollection [array]the media collection you want to get as array take true if it's multi or false if it's singleapiif you want to return JsonResponse or not
public function store(Request $request): RedirectResponse|JsonResponse { $response = Tomato::store( request: $request, //Required model: \App\Models\User::class, //Required validation: [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', ], message: __('User created successfully'), validationError: __('Error When Try To Store User'), redirect: 'admin.users.index', hasMedia: true, collection: [ 'avatar' => false, 'gallery' => true ], api: true, ); if($response instanceof JsonResponse){ return $response; } return $response->redirect; }
🔁 Update Request
this method returns RedirectResponse or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
requestthe request objectmodelthe model you want to getvalidationthe validation rules you want to usemessagethe message you want to return with the responsevalidationErrorthe message you want to return if the validation failedredirectthe redirect route you want to redirect tohasMediaif you want to get the media of the model or notcollection [array]the media collection you want to get as array take true if it's multi or false if it's singleapiif you want to return JsonResponse or not
public function update(Request $request, \App\Models\User $model): RedirectResponse|JsonResponse { $response = Tomato::update( request: $request, //Required model: $model, //Required validation: [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', ], message: __('User updated successfully'), redirect: 'admin.users.index', hasMedia: true, collection: [ 'avatar' => false, 'gallery' => true ], api: true, ); if($response instanceof JsonResponse){ return $response; } return $response->redirect; }
🔁 Destroy Request
this method returns RedirectResponse or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
modelthe model you want to getmessagethe message you want to return with the responseredirectthe redirect route you want to redirect toapiif you want to return JsonResponse or not
public function destroy(\App\Models\User $model): RedirectResponse|JsonResponse { $response = Tomato::destroy( model: $model, //Required message: __('User deleted successfully'), //Required redirect: 'admin.users.index', ); if($response instanceof JsonResponse){ return $response; } return $response->redirect; }
Request With Media
to make media handling work you must install spatie/laravel-medialibrary package and run the migration
composer require spatie/laravel-medialibrary php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="migrations" php artisan migrate
and your model must use HasMedia trait
use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; class User extends Model implements HasMedia { use InteractsWithMedia; }
Handel Alerts
and we have handel Toaster for you if you are using Splade it will working automatically and if you have yoeunes/toastr package it will working fine too. or you can use fetch toaster variable from session to get the flash messages.
Support
you can join our discord server to get support TomatoPHP
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security
Please see SECURITY for more information about security.
Credits
License
The MIT License (MIT). Please see License File for more information.
tomatophp/laravel-tomato 适用场景与选型建议
tomatophp/laravel-tomato 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「controllers」 「helpers」 「api」 「query」 「requests」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tomatophp/laravel-tomato 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomatophp/laravel-tomato 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tomatophp/laravel-tomato 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Opinionated Laravel Controllers extension
A package for generating annotations and drawing SwUi when working with Bitrix controllers.
Bullet development for Laravel Applications
HTML and form generation
Falsy helps you manage half-truths with PHP
Bundle of annotations to make it easier and faster to develop Rest APIs with Symfony.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-10
