Search code examples
phplaravellegacy

laravel legacy route url


i have 2 routes with POST methods

Route::post('/payment/checkOrder','Finance\PaymentCallbackController@checkOrder');
Route::post('/payment/paymentAviso', 'Finance\PaymentCallbackController@paymentAviso');

how can i create legacy links for these routes?

/plat.php?paysystem=5&method=checkOrder
/plat.php?paysystem=5&method=paymentAviso

Solution

  • You can have a single route that recieves a method string, and then call the desired functions according to it.

    Route::post('/payment/{method}','Finance\PaymentCallbackController@handler');
    // PaymentCallbackController.php 
    public function handler(Request $request){
       // make sure to validate what methods get sent here
       $this->{$request->method}($request); 
       // use $this if its in this controller, for otherControllers 
       // try something with the looks of  app('App\Http\Controllers\OtherControllerController')->{$request->method}->($request);
    }