asb/morphmtm
Composer 安装命令:
composer require asb/morphmtm
包简介
This package provides you with a module to automatically files need (Model,Migrations,...) add Morph many-to-many relations to your project along with commonly used basic commands.which minimizes the trial and error operation for you..
README 文档
README
Maybe for you, implementing a series of models and repetitive relationships is boring,
time-consuming and annoying, and you will have to copy your previous codes or refactor them,
which will be a waste of time.
This package provides you with a module to automatically files need (Model,Migrations,...) add Morph many-to-many relations to
your project along with commonly used basic commands.
which minimizes the trial and error operation for you.
how to use this package :
There is no need to define relationships anymore, and it is enough to Add the necessary Trait Has+yourModel (like this => hasStatus) in the models to which the Model is applied.
Requirements
The package requires PHP 8 or higher. The Laravel package also requires Laravel 10 or higher.
Quick Start
-
Installation:
composer require asb/morphmtm -
publish the package's configuration file by running:
php artisan vendor:publish --tag=morph-mtm-config -
Autoloading
By default, the module classes are not loaded automatically. You can autoload your modules using psr-4. For example:
"autoload": { "psr-4": { "App\\": "app/", "Rack\\": "Rack/" } }Tip: don't forget to run composer dump-autoload afterward
In an example to create a category module, I will explain how to use it. -
build module:
php artisan mtm:build *Modulename*php artisan mtm:build category
in continue the command, you will be asked to named, of course, you can confirm and pass the default value by pressed the enter key, but some default words may not be to your liking.`What is the Model Name [Category]: >[enter] What is the Model Plural Name [categories]: >[enter] What is the Model Relation Name [categoryable]: >categorizable //Here the default name of the relationship is not good, and we changed it.Tip: If You need to remove a module you can use this command
php artisan mtm:remove ModuleName -
Add the necessary Trait to your model:
//The class model requires these trait. use HasCategory; //has+yourModelName
-
Use predefined functions:
-
it gets all the models that have Category.
Tip: all functions is can call static with this format (MTM+modelName):\
one example : MTMCategory::getModelsHave('new')getModelsHave(string|ID $MTMmodel)
-
it gets all the Categories of Model.
getCategories(Model $model)
-
it checks the Model has this Category by Title or ID.
hasCategries(string|ID $model,string $MTMmodel)
-
it assigns a Category to the Model by Title or ID.
assignCategory(Model $model,string|ID $MTMmodel)
-
it adds a Category to the Model by Title or ID.
addCategory(Model $model,string|ID $MTMmodel)
updateCategory(Model $model,string|ID $MTMmodel,string|ID $newMTMmodel)
removeCategory(Model $model,string|ID $MTMmodel)
removeAllCategory(Model $model)
-
Using CRUD of Model in Module:
createCategoryModel(string $MTMmodel)
-
it gets all of Category And if it is called with "true" parameter, it will get all the deleted Category.
getAllCategoryModel(bool $onlyTrashed=false)
getCategoryModel(string|ID $MTMmodel)
updateCategoryModel(string|ID $MTMmodel, string $update_Category):
removeCategoryModel(string|ID $MTMmodel)
restoreCategoryModel(string|ID $MTMmodel)
-
asb/morphmtm 适用场景与选型建议
asb/morphmtm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 asb/morphmtm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 asb/morphmtm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-21
