advancelearn/search-elequent 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

advancelearn/search-elequent

最新稳定版本:1.0.1

Composer 安装命令:

composer require advancelearn/search-elequent

包简介

By installing this package, you can easily search in ElQuent Laravel, even between nested relations

README 文档

README

advancelearn/search-elequent

Introduction

By installing this package, you can easily search the values and columns of each model You can use this package in your Laravel projects

Installation

You can install the package with this command

composer require advancelearn/search-elequent

Now you can add the desired trait in any of the models that you want to be searchable

use Advancelearn\SearchElequent\Searchable;

class Order extends Model
{

    use Searchable;
    
    /**
     * Scope to perform a search operation.
     *
     * @param \Illuminate\Database\Query\Builder $query
     * @param string $searchText
     * @return \Illuminate\Database\Query\Builder
     */
    public function scopeSearch($query, string $searchText)
    {
        $searchColumns = ['order_number'];
        $relationColumns = [
            'address.user' => ['email'] // Nested relationship with address and user
        ];
        return $this->search($query, $searchText, $searchColumns, $relationColumns);
    }
    
    /**
     * Define the address relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\Relation
     */
    public function address()
    {
        // Define your address relationship logic here
    }
    
}

And for example, you can call this scope in your controller and pass the searched value to it:

$searchText = $request->q; // 'DE1253005'
// $searchText2 = "info@gmail.com";
return Order::search($searchText)->get();

Conclusion

The package you created to add search functionality to Eloquent models is a powerful tool in software development. Using this package, you will be able to perform complex searches in models as well as in tabular and relational relationships of models.

Among the main features of this package, the following can be mentioned:

Ease of use: By defining a simple scope in Eloquent models, this package provides the possibility of performing complex searches easily.

Support for relationships: You can also access tabular and relational relationships of models in your searches, which makes it possible to search for data related to a model.

Extensibility: This package allows you to add search features to all your Eloquent models, so you can create different searches based on your needs and match the unique features of your system.

Improved efficiency: With the ability to search the database based on specific conditions, you can quickly retrieve the data you need and improve the efficiency of your system.

By using this package, improve the ability to search and filter your data and make Laravel software development more simple and efficient.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-19