代码之家  ›  专栏  ›  技术社区  ›  Mohammad Naji

检查Laravel自定义验证规则中是否存在路由参数?

  •  0
  • Mohammad Naji  · 技术社区  · 7 年前

    考虑以下uri:

    • countries/{country}/persons/{person}/someAction
    • cities/{city}/persons/{person}/anotherAction

    我已经有规定了 check_country_contains_person 工作很好,但我应该把它扩展到 check_group_contains_person 在两个方法的验证类中使用。


    内部验证规则 passes 函数,如何检查 request()->route('country') 和/或 request()->route('city') 可获得的 还是不呢?

    请注意,如果我确定哪一个存在,我可以做其余的。 这只是检查路线参数的可用性。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Amirh    7 年前

    检查LARAVEL中的路由参数是否存在,只需检查一下:

    is_null($request->route('sample'))
    
    推荐文章