草庐IT

StorePostRequest

全部标签

「Goravel 上新」验证表单的三种新姿势,估计你只用过一种

验证用户输入的数据是我们开发中最常见的需求,Goravel提供三种验证姿势,个个简单好用!第一种:简单直接式根据表单内容直接校验:func(r*PostController)Store(ctxhttp.Context){validator,err:=ctx.Request().Validate(map[string]string{"title":"required|max_len:255","body":"required",})}第二种:自由定义式自定义验证数据:validator,err:=facades.Validation.Make(map[string]any{"name":"Gor

「Goravel 上新」验证表单的三种新姿势,估计你只用过一种

验证用户输入的数据是我们开发中最常见的需求,Goravel提供三种验证姿势,个个简单好用!第一种:简单直接式根据表单内容直接校验:func(r*PostController)Store(ctxhttp.Context){validator,err:=ctx.Request().Validate(map[string]string{"title":"required|max_len:255","body":"required",})}第二种:自由定义式自定义验证数据:validator,err:=facades.Validation.Make(map[string]any{"name":"Gor