2015-10-06 95 views
0

我需要在我的表單中使用GET才能生成url查詢字符串,但我也需要在我的路由中使用模型id。基本上,我想用表單提交生成的url查詢字符串來擴展show($ id)方法。但它沒有得到id。 (POST方法沒有得到它的。)Laravel 5:使用GET方法綁定模型時無法獲取id

這是我有:

fund.blade.php

{!! Form::model($fund, ['route' => 'funds.getQuery', 'method' => 'get'], $fund->id) !!} 
{!! Form::select('from', $years) !!} 
{!! Form::select('to', $years) !!} 
{!! Form::submit('Submit') !!} 
{!! Form::close() !!} 

routes.php文件

Route::get('funds/test/{funds}', [ 'as' => 'funds.getQuery', function($id){ 

$to = Input::get('to'); 

$from = Input::get('from'); 

$donations = Donation::whereBetween('Date_Submitted_Adjusted', [ 
       new Carbon($to), 
       new Carbon($from) 
      ]) 
      ->orderBy('Date_Submitted_Adjusted', 'asc') 
      ->get(); 

$urlString = url('funds', $parameters = [ 
    'id' => $id, 
    'from' => $from, 
    'to' => $to 
]); 

return $urlString; 

}]); 

我的節目/ {id}方法正常工作。我究竟做錯了什麼?

回答

0

在查看一些在線文檔時,看起來具體的對象ID應該與路由一起傳遞。代替這個:

{!! Form :: model($ fund,['route'=>'funds.getQuery','method'=>'get'],$ fund-> id)!!}

您可以試試以下內容嗎?

{!! Form :: model($ fund,['route'=> array('funds.getQuery',$ fund-> id),'method'=>'get'])!!}