2015-02-11 172 views
0

我有一個形式,我的模板文件:路由查詢字符串

   {{ Form::open(array('route' => 'get.index', 'method' => 'get')) }} 
        {{ Form::label('order', 'Order by') }} 
        {{ Form::select('order' , array('firstname' => 'First Name', 'lastname' => 'Last Name', 'state' => 'State')) }} 
        {{ Form::submit('Order results') }} 
       {{ Form::close() }} 

提交時,這種形式輸出一個GET查詢變量名稱的順序,所以我的網址是:

http://my.app/?order=firstname 

這是在get.index路線:

Route::get('/', array('uses' => '[email protected]', 'as' => 'get.index')); 

有一個簡單的方法來從一個改變URL上面類似 http://my.app/order/fistname/

回答

0

你可以有這樣的路線的唯一方法是使用:

Route::get('/order/{type}', array(
    'uses' => '[email protected]', 
    'as' => 'get.index' 
)); 

然後你就可以在你的控制器方法使用type參數:

public function index($type) { 

} 

但它會除非您在JavaScript中格式化表單動作值以適應此路線,否則不會與您的實際表單一起工作。

但是,如果你可以使用的東西比你可以輕鬆地用HTML標籤a做一個形式一樣,對於爲例:

Order by: 
<a href="{{ route('get.index', 'firstname') }}">firstname</a> 
<a href="{{ route('get.index', 'lastname') }}">lastname</a>