TaskDetailProjectRequest.php 2.3 KB
<?php
/**
 +----------------------------------------------------------------------------------------------------------------------
 * 数据验证层:TaskDetailProject 数据验证类
 +----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Http\Requests\Score
 * @package   App\Http\Requests\Score
 * @author    Richer <yangzi1028@163.com>
 * @date      2022年10月31日17:53:21
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Http\Requests\Score;

use App\Http\Requests\BaseRequest;

/**
 * Class TaskDetailProjectRequest
 *
 * @package App\Http\Requests\Score
 */
class TaskDetailProjectRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get custom attributes for validator errors.
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'project_score' => '原始分数',
            'score'         => '分数',
            'images'        => '图片',
        ];
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

        $data = [
//            'project_score' => 'required|numeric|min:0',
            'score'         => 'required|numeric|min:0|max:999999.99',
//            'score'         => 'required|numeric|min:0|max:999999.99|less_or_equal_than_field:project_score',
            'images'         => 'nullable|array',
        ];
        switch ($this->method()) {
            case 'POST':
            case 'PATCH':
            case 'PUT':
                return $data;
            case 'GET':
            case 'DELETE':
            default:
                return [];
        }
    }

    /**
     * 提示信息
     *
     * @return array
     */
    public function messages()
    {
        // 为了提示更准确,暂时不用框架自带的提示语句
        return [
            'less_or_equal_than_field' => '分数 不得大于 原始分数。',
        ];
    }
}