2121
2222class UpdateProduct extends FormRequest implements UpdateProductContract
2323{
24- public function rules ()
24+ public function rules (): array
2525 {
2626 return [
27- 'name ' => 'required|min:2 |max:255 ' ,
27+ 'name ' => 'required|min:1 |max:255 ' ,
2828 'sku ' => [
2929 'required ' ,
30+ 'max:255 ' ,
3031 Rule::unique ('products ' )->ignore ($ this ->route ('product ' )->id ),
31- ],
32- 'state ' => ['required ' , Rule::in (ProductStateProxy::values ())],
33- 'tax_category_id ' => 'sometimes|nullable|exists:tax_categories,id ' ,
34- 'shipping_category_id ' => 'sometimes|nullable|exists:shipping_categories,id ' ,
32+ ],
33+ 'state ' => ['required ' , ' max:255 ' , Rule::in (ProductStateProxy::values ())],
34+ 'tax_category_id ' => 'sometimes|nullable|integer| exists:tax_categories,id ' ,
35+ 'shipping_category_id ' => 'sometimes|nullable|integer| exists:shipping_categories,id ' ,
3536 'price ' => 'nullable|numeric ' ,
3637 'original_price ' => 'sometimes|nullable|numeric ' ,
3738 'stock ' => 'nullable|numeric ' ,
@@ -40,6 +41,18 @@ public function rules()
4041 'images ' => 'nullable ' ,
4142 'images.* ' => 'image|mimes:jpg,jpeg,pjpg,png,gif,webp ' ,
4243 'gtin ' => ['bail ' , 'sometimes ' , 'nullable ' , new MustBeAValidGtin ()],
44+ 'excerpt ' => 'sometimes|nullable|string|max:16383 ' ,
45+ 'meta_keywords ' => 'sometimes|nullable|string|max:2047 ' ,
46+ 'meta_description ' => 'sometimes|nullable|string|max:4095 ' ,
47+ 'ext_title ' => 'sometimes|nullable|string|max:511 ' ,
48+ 'subtitle ' => 'sometimes|nullable|string|max:255 ' ,
49+ 'slug ' => 'sometimes|nullable|string|max:255 ' ,
50+ 'description ' => 'sometimes|nullable|string ' ,
51+ 'weight ' => 'sometimes|nullable|numeric ' ,
52+ 'height ' => 'sometimes|nullable|numeric ' ,
53+ 'width ' => 'sometimes|nullable|numeric ' ,
54+ 'length ' => 'sometimes|nullable|numeric ' ,
55+ 'custom_attributes ' => 'sometimes|nullable|array ' ,
4356 ];
4457 }
4558
@@ -48,6 +61,12 @@ public function authorize()
4861 return true ;
4962 }
5063
64+ public function attributesForCreate (): array
65+ {
66+ $ except = ['id ' , 'deleted_at ' , 'updated_at ' , 'created_at ' , 'units_sold ' , 'last_sale_at ' ];
67+ return $ this ->validated (array_keys ($ this ->rules ()),['' ]);
68+ }
69+
5170 protected function prepareForValidation ()
5271 {
5372 $ this ->merge ([
0 commit comments