bjnstnkvc/builder-make-command
Composer 安装命令:
composer require bjnstnkvc/builder-make-command
包简介
Generate Eloquent Builder class for enhanced query building and model scope management.
README 文档
README
Generate Eloquent Builder class for enhanced query building and model scope management.
Features
- Dynamic query methods for
where,whereIn,whereLike,whereNot,whereNotIn,whereNotLike,orWhere,orWhereIn,orWhereLike,orWhereNot,orWhereNotInandorWhereNotLike. - Simplifies the construction of complex queries with readable method chains.
- Automatically handles method calls that are not natively supported by Laravel Query Builder by transforming them into appropriate query conditions.
Installation & setup
You can install the package via composer:
composer require bjnstnkvc/builder-make-command
The package will automatically register its service provider.
In case you would like to change the package defaults, you can do so by publishing the config:
php artisan vendor:publish --provider="Bjnstnkvc\BuilderMakeCommand\BuilderMakeCommandServiceProvider" --tag=make-builder-config
or stubs
php artisan vendor:publish --provider="Bjnstnkvc\BuilderMakeCommand\BuilderMakeCommandServiceProvider" --tag=make-builder-stubs
Usage
Once the package has been installed, you can run it via CLI the same way you would for any of the other CLI commands.
php artisan make:builder UserBuilder
By default, the command will try figure out the name of the model from the name of the builder (E.g. UserBuilder will
attempt to look for User model).
Additionally, you can pass a model name as a second argument.
php artisan make:builder UserBuilder User
In case the Builder already exists, you can pass an optional --force argument which will overwrite the existing class.
php artisan make:builder UserBuilder User --force
Note: By forcing the Builder command, all custom methods you've added to the Builder will be overwritten so be cautious.
If you simply call the command, without any arguments, Laravel will prompt you for input.
php artisan make:builder
What should the builder be named? > UserBuilder
What is the model name? [User] >
Overwrite existing file? (yes/no) [no] >
The name of the Model has been derived from the Builder name and set as a default. Confirm by pressing ENTER or enter the name of the Model.
In case the file already exists, you will be prompted whether you would like to overwrite the existing file.
Once the command has been run, the Builder class will be created inside app\Models\Builders folder.
In order to use it inside your models, add HasDynamicBuilder trait to your model:
use Bjnstnkvc\BuilderMakeCommand\Concerns\HasDynamicBuilder; class User extends Model { use HasDynamicBuilder; }
Once added, dynamic where clauses for every Model column is added as an Eloquent method.
User::whereId(mixed $operator = null, mixed $value = null, string $boolean = 'and'); User::whereIdNot(mixed $operator = null, mixed $value = null, string $boolean = 'and'); User::whereIdIn(array $values, string $boolean = 'and', bool $not = false); User::whereIdNotIn(array $values, string $boolean = 'and'); User::whereIdLike(string $value, bool $caseSensitive = false, string $boolean = 'and', bool $not = false); User::whereIdNotLike(string $value, bool $caseSensitive = false, string $boolean = 'and', bool $not = false); User::orWhereId(mixed $operator = null, mixed $value = null); User::orWhereIdNot(mixed $operator = null, mixed $value = null); User::orWhereIdIn(array $values); User::orWhereIdNotIn(array $values); User::orWhereIdLike(string $value, bool $caseSensitive = false); User::orWhereIdNotLike(string $value, bool $caseSensitive = false); // Methods for other database columns.
Naturally, these methods can be chained on:
User::whereId(1) ->orWhereNameNot('John') ->first();
User::whereId('>', 1) ->orWhereEmail('email@example.com') ->first();
In case you need to group several "where" clauses within parentheses in order to achieve your query's desired Logical Grouping, you can do the following:
use App\Models\Builders\UserBuilder; User::whereName('John') ->where(function (UserBuilder $query) { $query->whereEmail('email@example.com') ->orWhereTitle('Admin'); }) ->first();
In case you would like to generate the Builder method signatures as a mixin, you can use the --mixin flag:
php artisan make:builder UserBuilder User --mixin
The mixin will be created inside .builder.mixin.php file and automatically imported into the Builder class.
bjnstnkvc/builder-make-command 适用场景与选型建议
bjnstnkvc/builder-make-command 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「query」 「builder」 「laravel」 「eloquent」 「scope」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bjnstnkvc/builder-make-command 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bjnstnkvc/builder-make-command 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bjnstnkvc/builder-make-command 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Query filtering in your frontend
A Sphinx Query Builder extension for the Laravel Database package
Anax Database Active Record module for model classes.
Database/ORM-agnostic query construction helper
A simple package to create tables in Discord messages.
Create mail from controller action render
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-21