承接 mhamzeh/presenter-filter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mhamzeh/presenter-filter

Composer 安装命令:

composer require mhamzeh/presenter-filter

包简介

README 文档

README

Introduction

The package allows you to create two types of classes: filter class and presenter class

Filter

This package allows you to easily handle database filtering through query strings.

example: /users?status=1&name='kami'

Presenter

Sometimes our models get too fat, and that can make our development a lot harder. In this case, we use a second class that has the same function as the model and is used as a second model, and the Harrow method can be included in this class.

Installation

you can install the package via composer:

composer require mhamzeh/presenter-filter

You Must by publishing configuration by issuing following artisan command php artisan vendor:publish.

Usage

You have access to two commands and you can use them to create your own filter and presenter classes

make:filter command

You can use the following command to create a new filter.

php artisan make:filter UserFilter

This will create a new filter in the app/Filters directory.

options:

1-You can add the model to the command

‍‍‍‍‍‍php artisan make:filter UserFilter --model=User

Used by default Models folder If you have saved models elsewhere, change the config Modules of this folder

make:presenter Command

You can use the following command to create a new Presenter

php artisan make:presenter UserPresenter

options:

1- You can add the model to command

php artisan make:presenter UserPresenter --model=User

Example With Filter

Let's say you want to use filterable on User model. You will have to create the filter class App/Filters/PostFilter.php (php artisan make:filter PostFilter --model=Post)

If you use the --model option, filterable will be added directly to the model

<?php
namespace App\Filters;

use mhamzeh\packageFp\Filters\contracts\QueryFilter;

class UserFilter extends QueryFilter
{
    public function name($value){
        return $this->builder->where('name','LIKE',"%$value%");        
    }
}

Now you need to add local scope to your model if you have not used the --model option:

use mhamzeh\packageFp\Filters\contracts\Filterable;
...
class User extends Model
{
    use Filterable;
    ...
}

Finaly, call the scope in controller like so:

use App\Filters\UserFilter;
...
public function index()
{
    return User::filters(new UserFilter())->paginate();
}

Example With Presenter

Let's say you want to use Presentable And introduce the presenter class on User model. You will have to create the filter class App/Presenter/UserPresenter.php (php artisan make:presenter UserPresenter --model=User)

If you use the --model option, Presentable and presenter class will be added directly to the model

<?php
namespace App\Presenter;

use mhamzeh\packageFp\Presenter\Contracts\Presenter;

class UserPresenter extends Presenter
{
    public function full_name(){
         return $this->entity->name ." ".$this->entity->full_name;        
    }
}

Now you need to add local scope to your model if you have not used the --model option:

use mhamzeh\packageFp\Presenter\Contracts\Presentable;
...
class User extends Model
{
    use Presentable;
    protected $presenter = UserPresenter::class;

    ...
}

Finally you can use this method in your Blade or Api Resources or Controller for example Blade:

 @foreach($users as $user)
     <div>
          <p>fullname : $user->present()->full_name </p>
      </div>
 @endforeach

in Api Resources:

class UserResource extends JsonResource
{
   /**
    * Transform the resource into an array.
    *
    * @param \Illuminate\Http\Request $request
    * @return array
    */
   public function toArray($request)
   {
       return [
            'id'=>$this->id,
            'full_name'=> $this->present()->full_name,
            'email'=>$this->email
        ];
   }
}

mhamzeh/presenter-filter 适用场景与选型建议

mhamzeh/presenter-filter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 11, 最近一次更新时间为 2020 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「mohammad Hamzeh」 「laravel-presenter-filter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mhamzeh/presenter-filter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mhamzeh/presenter-filter 我们能提供哪些服务?
定制开发 / 二次开发

基于 mhamzeh/presenter-filter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-09