Getting GET “?” variable in laravel

前端 未结 8 806
夕颜
夕颜 2020-12-16 08:41

Hello I\'m creating API using REST and Laravel following this article.

Everything works well as expected.

Now, I want to map GET request to recognise variabl

相关标签:
8条回答
  • 2020-12-16 09:46

    We have similar situation right now and as of this answer, I am using laravel 5.6 release.

    I will not use your example in the question but mine, because it's related though.

    I have route like this:

    Route::name('your.name.here')->get('/your/uri', 'YourController@someMethod');
    

    Then in your controller method, make sure you include

    use Illuminate\Http\Request;
    

    and this should be above your controller, most likely a default, if generated using php artisan, now to get variable from the url it should look like this:

      public function someMethod(Request $request)
      {
        $foo = $request->input("start");
        $bar = $request->input("limit");
    
        // some codes here
      }
    

    Regardless of the HTTP verb, the input() method may be used to retrieve user input.

    https://laravel.com/docs/5.6/requests#retrieving-input

    Hope this help.

    0 讨论(0)
  • 2020-12-16 09:47

    In laravel 5.3 $start = Input::get('start'); returns NULL

    To solve this

    use Illuminate\Support\Facades\Input;
    
    //then inside you controller function  use
    
    $input = Input::all(); // $input will have all your variables,  
    
    $start = $input['start'];
    $limit = $input['limit'];
    
    0 讨论(0)
提交回复
热议问题