mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 06:30:49 +00:00
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class GoodsRequest 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,id'],
|
|
'title' => ['required', 'string', 'max:255'],
|
|
'img_url' => ['required', 'string', 'max:255'],
|
|
'type_id' => ['required', 'integer', 'exists:goods_types,id'],
|
|
'brand_id' => ['integer', 'exists:goods_brands,id'],
|
|
'goods_code' => ['required', 'alpha_dash', 'max:32', Rule::unique('goods')->ignore(request('goods_id'))],
|
|
];
|
|
}
|
|
|
|
public function arrayRules($arrayName)
|
|
{
|
|
$arrayRules = [];
|
|
$rules = $this->rules();
|
|
foreach ($rules as $key => $val) {
|
|
$arrayRules[$arrayName . $key] = $val;
|
|
}
|
|
|
|
return $arrayRules;
|
|
}
|
|
}
|