kanata-php/forklift
Composer 安装命令:
composer require kanata-php/forklift
包简介
Livewire package to move models around.
README 文档
README
Forklift
Laravel Livewire Component
composer require kanata-php/forklift
Move assets in a predictable and easy manner with Eloquent and Livewire.
Dependencies
- Laravel
- Livewire
- AlpineJS
Installation
Step 1
Install composer package:
composer require kanata-php/forklift
Step 2
Publish the assets registered in the Service Provider:
php artisan vendor:publish --provider="Kanata\Forklift\ForkliftServiceProvider"
After this you'll find the assets at the directory resources/views/vendor/forklift. At the current version the initial assets are only presentable for projects usign Tailwind CSS.
Step 3
Implement the Kanata\Forklift\Interfaces\AssetRepositoryInterface for the component to know how to interact with your project's models. You'll create one per case (e.g. if you need to move nested directories, one repository, then if you need to move documents through directories, another repository).
Methods:
-
AssetRepositoryInterface::changeCurrentLocation- This method returns current location's "sub locations". This is equivalent to sub folders when you have a folder based structure like a filesystem navigation. -
AssetRepositoryInterface::moveAsset- This method executes the movement between locations of the asset being managed. -
AssetRepositoryInterface::findLocation- This method finds the current location object.The output must be an array with the following fields:
- id (int) - primary key
- title (string) - location's title
- parent (int) - parent location (for nested locations)
Usage
Basics
Let's assume we have a filesystem structure. In this structure you have documents and directories. This package adds a dropdown that allows quickly moving assets in the directory structure.
For such, using eloquent, we would have the models:
- Directory - that keeps the directories structure, having subdirectories and documents inside them.
Example migration:
Schema::create('directories', function (Blueprint $table) { $table->id(); $table->string('title', 40); $table->foreignId('parent')->nullable(); $table->timestamps(); });
- Document - that keeps the documents.
Example migration:
Schema::create('documents', function (Blueprint $table) { $table->id(); $table->string('title', 40); $table->longText('content'); $table->foreignId('directory_id')->nullable(); $table->timestamps(); });
The following component is the dropdown to move documents:
@livewire('forklift-dropdown', [
'currentLocationId' => $document->directory_id,
'locationType' => \App\Models\Directory::class,
'assetId' => $document->id,
'assetType' => \App\Models\Document::class,
'assetRepository' => App\Repositories\DocumentAssetRepository::class,
'parentField' => 'directory_id',
])
The following component is the dropdown to move directories:
@livewire('forklift-dropdown', [
'currentLocationId' => $directory->parent,
'locationType' => \App\Models\Directory::class,
'assetId' => $directory->id,
'assetType' => \App\Models\Directory::class,
'assetRepository' => App\Repositories\DirecotryAssetRepository::class,
'parentField' => 'parent',
])
You can find an example laravel project here.
Events
Forklift dispatches 2 events, in 3 different levels. The 2 events are:
Kanata\Forklift\Events\AssetMoved- Triggered after a successful return from the asset repository.Kanata\Forklift\Events\AssetMoveFailed- Triggered after a fail return from th asset repository.
The 3 levels that these events are dispatched are:
- Laravel Events (https://laravel.com/docs/9.x/events#main-content)
- Livewire Events (https://laravel-livewire.com/docs/2.x/events)
- Browser events via Livewire (https://laravel-livewire.com/docs/2.x/events#browser)
Todo
- Change UI when backend error happens.
kanata-php/forklift 适用场景与选型建议
kanata-php/forklift 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 103 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「file」 「directory」 「laravel」 「folder」 「livewire」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kanata-php/forklift 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kanata-php/forklift 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kanata-php/forklift 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
LDAP user provider bundle for Symfony 6.4
Laravel Media Popup to upload/view the files
Simple class for encapsulating file directory object.
PMVC Plugin for File information
Mapper for accessing resources in KWCMS
统计信息
- 总下载量: 103
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-12

