0

每当我尝试通过浏览器或邮递员访问我在 Lumen 中的帖子的网址时,我都会收到以下错误

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);
    }

有人可以告诉我我做错了什么

4

0 回答 0