Reputation: 1478
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">
Upvotes: 3
Views: 9116
Reputation: 131
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!
Upvotes: 2
Reputation: 163798
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
Upvotes: 1
Reputation: 13703
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!
Upvotes: 2