php - Judgment problem in middleware
淡淡烟草味
淡淡烟草味 2017-06-21 10:10:43
0
4
736

I pass a parameter of age=22 through the get method, and $request->age can get the corresponding value. However, when executing the 13th line of code in the figure below, why does the if judgment pass and 14 lines of content are directly output?

淡淡烟草味
淡淡烟草味

reply all(4)
大家讲道理
你的访问的url不对的,
Route::get('/ages=test/{age}',['middleware'=>'test',function($age){
    return "年龄符合标准";
}]);这个路由 传参的时候,age只需要传数字,不要age=22 这个就是字符串了,所以dd($request->age)
出来是“age=22”,数字比较的时候,字符串转换为0 ,所以一直进入if语句
我想大声告诉你

Try writing it like this

if(($request->age) <18)
漂亮男人


The very weird url
should be: www.laraveltest.com:8888/agetest/22
or: www.laraveltest.com:8888/agetest?age=22

The url you visited is wrong

大家讲道理

I don’t understand the usage of passing parameters at all. Are you new to laravel? Use the wrong one. The {age} you wrote is just a placeholder-like thing. The age=22 followed by your route is equivalent to the parameter age=22. You can just follow 22 without adding age. Thank you

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template