TP 검증 규칙 Validate

3288 단어
use think\Validate;

php
namespace app\common\model;

use think\Validate;
use think\Db;

class InvoiceRecords extends BaseModel
{
    protected $table = 't_invoice_record';

    protected $rule = [
        'type'  => 'in:1,2',
        'invoice_tel'  => 'mobile',
        'email'  => 'email',

    ];
    protected $message = [
        'type' => ' ',
        'invoice_tel' => ' ',
        'email' => ' ',

    ];

    public function addInfoData($member_id, $type, $money, $invoice_name, $invoice_tel, $email, $taxpayer_number, $id)
    {
        $data = [
            'type' => $type,
            'invoice_tel' => $invoice_tel,
            'email' => $email,
        ];
        $validate = new Validate($this->rule, $this->message);
        if (!$validate->check($data)) {
            return ['code' => 400, 'msg' => $validate->getError()];
        }
    }
}

좋은 웹페이지 즐겨찾기