每当我尝试通过浏览器或邮递员访问Lumen中的帖子的URL时,都会出现以下错误
Whoops, looks like something went wrong.
MethodNotAllowedHttpException
in RoutesRequests.php
at Application->handleDispatcherResponse(array(2, array('POST')))
in RoutesRequests.php
从下面的web.php查看路由代码
$router->post('gen','VoucherController@generateVoucherCode');
查看generateVoucherCode中的代码
class VoucherController extends Controller
{
public function generateVoucherCode(Request $request){
// generate 16 digit random no.
$random1 = rand(1111, 9999);
$random2 = rand(1111, 9999);
$random3 = rand(1111, 9999);
$random4 = rand(1111, 9999);
$voucher_code = ($random1."-".$random2."-".$random3."-".$random4);
$today = date("Y-m-d");
$use_once = "yes";
$request->request->add( ['voucher_code' => $voucher_code,
'use_once' => $use_once,
'date_used' => $today,
'date_created' => $today]);
Voucher_code::create($request->all());
return response()->json($voucher_code);
}
有人可以告诉我我做错了什么吗