Laravel将路由参数转换为Integer [英] Laravel cast route parameter to Integer

查看:237
本文介绍了Laravel将路由参数转换为Integer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢路由模型绑定的想法.

是否有类似的方法将参数(字符串)转换为Intergers?

Is there a similar way to cast parameters (which are Strings) to Intergers?

原因是我经常具有参数yearmonth,但是我希望将其作为Integer使用,因为数据库似乎以不同的方式处理String和Integer.

The reason is that I often have the parameters year and month, but I would like to have it as an Integer, because the database seems to handle String and Integers in different ways.

推荐答案

是的.您可以使用Route Binding类似于我在 .不幸的是,它存在但在Laravel文档中没有记录.

Yes there is. You can use Route Binding similar to what I answered here. It's unfortunate that it exists but is not documented in the Laravel docs.

这篇关于Laravel将路由参数转换为Integer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆