Lumen 5.6.4 get post route throwing MethodNotAllowedHttpException

99封情书 提交于 2020-01-06 05:30:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!