LARAVEL 5.0 PHP 5.4.45
I have a route that is shaped like this :
/app/Http/routes.php
Route::get('/clients/search/{id}', 'ClientController@searchById')->where('id', '[0-9]+');
Route::get('/clients/search/{text}', 'ClientController@searchByText')->where('text', '[a-zA-Z]');
I will not print my view here but it simply search for the exact client (case id) or the first 10 clients (case text).
Then I want to create a search form. I created the route :
/app/Http/routes.php
// Route::get('/clients/search/{id}', 'ClientController@searchById')->where('id', '[0-9]+');
// Route::get('/clients/search/{text}', 'ClientController@searchByText')->where('text', '[a-zA-Z]');
Route::get( '/clients/search', 'ClientController@search');
The controller for this route :
/app/Http/Controllers/ClientController.php
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class ClientController extends Controller {
// Controllers for the 'searchById' and 'searchByText'
public function search() {
return view('client.search.search', [
'title' => 'Client search form',
'title_sub' => ''
]);
}
}
And the view for this search form :
/ressources/view/client/search/search.blade.php
<form action="/clients/search/INPUT HERE ?" method="get">
<div class="input-group">
<input id="newpassword" class="form-control" type="text" name="password" placeholder="Id de client, nom, prénom, ...">
<span class="input-group-btn">
<button id="button_search" class="btn green-haze" type="submit"><i class="fa fa-search fa-fw"></i></button>
</span>
</div>
</form>
QUESTION
How can I, before submit, pass an input as a part of my action
attribute for my form ? The point is to be able to launch those kind of requests :
- /clients/search/26
- /clients/search/Mike%20%Folley
- /clients/search/Paris
So my controllers handling this route could do the job. Is there any way to do that ? Or should I go for JavaScript solution (which make me sad a bit) ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire