[英]Laravel 5.5 best way to validate API endpoint parameters
路線
Route::get('attendence/{year?}/{name?}/{category?}, 'EmployeesController@users');
控制器動作
function users($year=null, $name=null, $category= null){
}
我的要求是不要拋出異常,而是向用戶顯示以下所有URL的有意義的消息。
http://localhost:8080/2012/john/travel
http://localhost:8080/undefined/john/travel
http://localhost:8080/undefined/john
http://localhost:8080/john
換句話說,應驗證可變年份的數字值,名稱和字母類別。
注意:我正在使用Laravel流明
任何幫助都值得贊賞
驗證-https: //lumen.laravel.com/docs/5.5/validation
正則表達式約束+自定義異常處理程序-https: //lumen.laravel.com/docs/5.5/routing#parameters-regular-expression-constraints https://lumen.laravel.com/docs/5.2/errors#the-exception -處理程序
我想第一個很清楚。 第二個,您可以捕獲路由異常,並通過有意義的消息呈現視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.