<?php

namespace App\Http\Requests\Validators\Api\MobileWeb;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Validator;

class InventoryValidator extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    // 新增验证器
    public function indexValidator($data)
    {
        // 自定义错误消息
        $messages = [
            'gs_bid.required' => '请选择品牌',
        ];

        // 数据验证
        $validator = Validator::make($data, [
            'gs_bid' => 'required',
        ], $messages);

        // 判断数据验证是否成功
        if ($validator->fails()) {
            return $validator->errors();
        }
    }

    // 修改密码验证器
    public function editValidator($data)
    {
        // 自定义错误消息
        $messages = [
            'goodid.required' => '参数错误',
            'goodid.integer' => '参数错误',
            'goodid.min' => '参数错误',
            'goodnum.required' => '参数错误',
            'goodnum.integer' => '参数错误',
            'goodnum.min' => '参数错误',
            'brand.required' => '参数错误',
            'brand.string' => '参数错误',
        ];

        // 数据验证
        $validator = Validator::make($data, [
            'goodid' => 'required|integer|min:1',
            'goodnum' => 'required|integer|min:0',
            'brand' => 'required|string',
        ], $messages);

        // 判断数据验证是否成功
        if ($validator->fails()) {
            return $validator->errors();
        }
    }
}
