PHP code example of mzh / hyperf-helper

1. Go to this page and download the library: Download mzh/hyperf-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mzh / hyperf-helper example snippets


use GetQueryHelper;

        //获得模型
        $userModel = User::query();
        //(1)可以再模型设置条件,join 之类的
        $userModel->where('id', 1)->where('status', 1);

        //引入QueryHelper  第一个参数传模型对象,第二个参数传 数组分页查找
        $query = $this->QueryHelper($userModel, $data);

        //如果不用(1)方法也可以在引入引入QueryHelper后再对模型进行
        $query->query->where('id', 1);
        $query->query->join('','','','');
        //...等等所有模型操作

        // 切入url参数,接收 username 和 keywords 并使用 like 查询,接收 user_id is_top 使用 eq 查询
        $query->equal('user_id,is_top');
        $query->like('username,keywords');
        //用法1
        $query->timeBetween('字段');
        $query->timeBetween([
            '开始时间字段',
            '结束时间字段'
        ]);
        $query->dateBetween('日期字段');
        $query->dateBetween([
            '开始日期字段',
            '结束日期字段'
        ]);
        //启用自动分页 paginate 第一个参数可选,列表返回字段,第二个参数可以传一个匿名函数 可以再里面修改返回列表集合
        return $query->paginate();

shell script
php bin/hyperf.php gen:api User 用户控制器 UserService 介绍
执行后会在 App/Controller里生成User.php 类

#多级目录
php bin/hyperf.php gen:api Api/v1/User 用户控制器 UserService 介绍
执行后会在 App/Controller/api/v1/下生成User.php 类
shell script
php bin/hyperf.php gen:service User
执行后会在 App\Serivce 里生成UserService.php 类

shell script
php bin/hyperf.php gen:validate User
执行后会在 App\Validate 里生成UserValidation.php 类并把默认规则填入