首先,让我们定义一个规则:用户只能访问自己创建的文章。 facades.Gate.Define("update-post",func(ctxcontext.Context,argumentsmap[string]any)access.Response{ user:=ctx.Value("user").(models.User) post:=arguments["post"].(models.Post) ifuser.IDpost.UserID{ returnaccess.NewAllowResponse() }else{ returnaccess.NewDenyResponse("error...

  wdb9fu0BUnWz   2023年11月02日   43   0   0 Go

验证用户输入的数据是我们开发中最常见的需求,Goravel提供三种验证姿势,个个简单好用! 第一种:简单直接式 根据表单内容直接校验: func(rPostController)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{...

  wdb9fu0BUnWz   2023年11月02日   113   0   0 Go

关于Goravel Goravel是一个功能完备、具有良好扩展能力的Web应用程序框架。作为一个起始脚手架帮助Golang开发者快速构建自己的应用。框架风格与Laravel保持一致,让PHPer不用学习新的框架,也可以愉快的玩转Golang! ORM模块上新「模型关联」,好用的飞起,有码有真相! 定义模型 一个用户可以发布多篇文章 typeUserstruct{ orm.Model Namestring Posts[]Post } typePoststruct{ orm.Model UserIDuint Namestring } 查找(同时预加载关联模型) varusermodels.Use...

  wdb9fu0BUnWz   2023年11月02日   89   0   0 Go
关注 更多

空空如也 ~ ~

粉丝 更多

空空如也 ~ ~