问题
whenever i try to access my url for a post in Lumen through the browser or postman i get the below error
Whoops, looks like something went wrong.
MethodNotAllowedHttpException
in RoutesRequests.php
at Application->handleDispatcherResponse(array(2, array('POST')))
in RoutesRequests.php
see route code from web.php below
$router->post('gen','VoucherController@generateVoucherCode');
see code from 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);
}
Can someone pls tell me what I am doing wrongly
来源:https://stackoverflow.com/questions/51904599/lumen-5-6-4-get-post-route-throwing-methodnotallowedhttpexception