Laravel:如何使用Form POST中的参数在Route :: post中使用?

This my current POST route. Route::post('/eAPI', 'ApiController@eAPI');

I wanted to make it like

Route::post('/q={$number}', 'ApiController@eAPI');

But in my form.

<form action="{{url('/eAPI')}}" method="post" id="search">
  <div class="form-group">
    <label for="number" class="col-md-4 control-label">Telephone Number to search :</label>

    <div class="col-md-6">
      <input class="form-control" id="number" name="number" placeholder="Phone (eg. 5551234567)" required>


    </div>
  </div>

  <div class="col-md-2">
    <input type="submit" name="name" value="Find" class="btn btn-success">
  </div>
</form>

Now, I want to put a variable in this part, something like this.

<form action="{{url('/?q=$number')}}" method="post" id="search">

</div>

In post request you should do it like this:

Route::post('/eAPI/{q}', 'ApiController@eAPI')->name('my_route');

And in HTML Form:

<form action="{{ route('my_route', ['q' => '4']) }}" method="post" id="search">
</form>

And inside controller you can retrieve it as:

Class ApiController {

    public function eAPI($q) {
        // Use $q here ...
    }

}

Hope this helps!

I never did and will never do this with post requests, but it works with get requests:

$q = request()->q;

And you don't need to add this to the route: q={$number}, just add parameters to url: ?q=value1&s=value2&c=value3

This works for me [method post and url has ?q=someValue] :

 public function eApi(Request $request){
     $q = $request['q'];
 }

This code will get all params in post and get method

$request->all()

Hope it helps!