1、路由基本使用实例
a.默认示例
Route::get('/',function(){
return view('welcome');
});
b.Get请求示例,对页面常见的请求有get post
Route::get('/home',function(){
return 'Hello world !';
});
c.Post请求示例
Route::get('/testPost',function(){
$csrf_token = csrf_token();
$form = <<<FORM
<form method="post" action="/post">
<input type="hidden" name="_token" value="$csrf_token">
<input type="submit" name="btn" value="提交">
</form>
<<<FORM;
return $form;
});
Route::post('/post',function(){
return 'Hello Laravel';
})
d.其他便捷路由
Route::match(['get','post'],'/hello',function(){
return 'vagrant add box metadata.json';//match 匹配多种请求
});
Route::any('/hello',function(){
return 'bash init.sh'; //any 匹配任意请求
});
2、路由参数使用示例
a.必选参数
Route::get('/hello/{name}',function($name){
return "hello {$name} !";
});
Route::get('/hello/{n
laravel之http请求路由
最新推荐文章于 2024-01-18 10:52:18 发布