erp/app/Http/Requests/GoodsSkuRequest.php

49 lines
1.2 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class GoodsSkuRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'id' => ['sometimes', 'required', 'integer', 'exists:goods_skus,id'],
'goods_id' => ['sometimes', 'required', 'integer', 'exists:goods,id'],
'title' => ['required', 'string', 'max:255'],
'sku_code' => ['required', 'distinct', 'alpha_dash', 'max:32'],
'status' => ['required', 'integer', Rule::in([0, 1, 2])],
'num' => ['required', 'integer'],
'cost' => ['required', 'numeric'],
];
}
public function arrayRules($arrayName)
{
$arrayRules = [];
$rules = $this->rules();
foreach ($rules as $key => $val) {
$arrayRules[$arrayName . $key] = $val;
}
return $arrayRules;
}
}