Laravel route with parameters

前端 未结 3 1578
陌清茗
陌清茗 2021-01-18 08:28

Am using laravel route for approving some form from email. So i have encrypted some variables and created link which is like



        
3条回答
  •  悲哀的现实
    2021-01-18 09:08

    There are many methods to do this.

    Method 1

    If you make the url like below:

    Approve;
    

    You can make route with parameters as like below.

     Route::get('approveRequest/{par1}/{par2}/{par3}', 'ApproveController@approve');
    

    And in your function get the respective parameter as following:

    public function approve($par1,$par2,$par3,) 
    {
         $id = $par1;
         $gsID = $par2;
         .... and so on for all your variables.
     }
    

    Method 2 use request method:

    If your url is like:

      Approve;
    

    Then define Route Like:

       Route::post('approveRequest', 'ApproveController@approve');
    

    Then in your controller function you get parameters as below:

    Use Request after the namespace in youe controller class

                namespace App\Http\Controllers;
                use Illuminate\Http\Request;
    
                class SomeClassController extends Controller {
    
                    public function approve(Request $request) 
                   {
                     $id = $request->id;
                     $gsID = $request->get('gsID');
                     .... and so on for all your variables.
                    }
                 }
    

提交回复
热议问题