lumenweb.php中定义路由,post方法提交age参数,经过中间件auth_age:$app->group(['middleware'=>'auth_age'],function()use($app){$app->group(['namespace'=>'\App\Account\Http\Controllers'],function()use($app){$app->post('/age',['as'=>'age','uses'=>'UserController@getAge']);});});app.php中已注册auth_age:$app->routeMiddleware(['auth_age'=>App\Account\Http\Middleware\AgeMiddleware::class,]);中间件AgeMiddleware.php:publicfunctionhandle($request,Closure$next){//echo$request->input('age');exit;//post到这里能获取到if($request->input('age')
2 回答
慕侠2389804
TA贡献1719条经验 获得超6个赞
自己回答:UserController.php..useIlluminate\Http\Request;...publicfunctiongetAge(Request$request){$age=$request->input('age');return"ageis".$age.".";}
江户川乱折腾
TA贡献1851条经验 获得超5个赞
$input=$request->all();//或者$age=$request->input('age');因为经常写API,我个人的习惯是用all()$check_result=check_required_data($input,['login_type','login_value']);if($check_result['code']==404){returnresponse(['msg'=>$check_result['msg']],$check_result['code']);}.../***检测需要的变量**@paramarray$input_data*@paramarray$required_data**@returnarray*/publicfunctioncheck_required_data($input_data=[],$required_data=[]){foreach($required_dataas$value){if(idx($input_data,$value,false)===false){$dis=str_replace('_','',$value);//自定义变量习惯return['msg'=>'require'.$dis,'code'=>'404'];}}return['msg'=>'success','code'=>'200'];}
添加回答
举报
0/150
提交
取消