定制 mphpmaster/model-query-selector 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mphpmaster/model-query-selector

最新稳定版本:1.2.2

Composer 安装命令:

composer require mphpmaster/model-query-selector

包简介

Laravel ModelQuerySelector - SQL Column Selection Utility

README 文档

README

Laravel ModelQuerySelector is a powerful package designed to simplify the construction of SQL select queries in Laravel applications. It offers a fluent interface for building column selections and table aliases, streamlining the creation of complex queries.

Features

  • Fluent Interface: Easily construct SQL select queries using a fluent and intuitive syntax.
  • Column Selections: Efficiently specify columns to be selected in the query.
  • Table Aliases: Define table aliases for improved query readability and clarity.
  • Dynamic and Static Methods: Use both static and dynamic method calls to create queries.

Dependencies:

  • php >=8.1 REQUIRED IN YOUR PROJECT
  • laravel >=8 REQUIRED IN YOUR PROJECT
  • illuminate/support >=8 composer will install it automaticly
  • laravel/helpers ^1.5 composer will install it automaticly

Installation

You can install the Laravel ModelQuerySelector package via Composer. Run the following command in your terminal:

composer require mphpmaster/model-query-selector

The package will automatically register its service provider.

Usage

Helper Function

You can use the mqs helper function to create an instance of ModelQuerySelector:

use MPhpMaster\ModelQuerySelector\ModelQuerySelector;

// Usage example
$querySelector = mqs(User::class, 'u');
dump($querySelector); // Outputs: "users as u"

Manual Instantiation

You can also manually instantiate ModelQuerySelector as follows:

use MPhpMaster\ModelQuerySelector\ModelQuerySelector;
use App\Models\User;

// Static method call to qc()
$querySelector = ModelQuerySelector::qc(['column1', 'column2'], User::class);
dump($querySelector); // Outputs: "users.column1, users.column2"

// Static method call to table()
$querySelector = ModelQuerySelector::table(User::class, 'alias');
dump($querySelector); // Outputs: "users as alias"

// Dynamic method call to table()
$querySelector = new ModelQuerySelector();
$querySelector->table(User::class, 'alias');
dump($querySelector); // Outputs: "users as alias"

// Dynamic method call to qc()
$querySelector = new ModelQuerySelector(User::class);
$querySelector->qc(['column1', 'column2'], 'alias');
dump($querySelector); // Outputs: "alias.column1, alias.column2"

toString Method

The toString method returns the string representation of the ModelQuerySelector instance:

use MPhpMaster\ModelQuerySelector\ModelQuerySelector;

$querySelector = mqs(User::class, 'u');
echo $querySelector->toString(); // Outputs: "users as u". same as: `echo trim($querySelector);`

License

The Laravel ModelQuerySelector package is open-source software licensed under the MIT license.

Contributing

Contributions are welcome! Feel free to submit bug reports, feature requests, or pull requests on GitHub.

Support

For any questions or issues, please open an issue on GitHub.

Credits

This package was created and is maintained by hlaCk.

Acknowledgements

Special thanks to the Laravel community for their continued support and contributions.

Stand with Palestine 🇵🇸 #FreePalestine

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-20