Laravel 5: 使用带有模型绑定的 GET 方法时无法获取 ID
Laravel 5: Can't get id when using GET method with model binding
我需要在我的表单中使用 GET 来生成一个 url 查询字符串,但我还需要在我的路由中使用模型 ID。基本上,我想用表单提交生成的 url 查询字符串扩展 show($id) 方法。但它没有得到 id。 (POST 方法也没有得到它。)
这是我的:
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;
}]);
我的 show/{id} 方法运行良好。我做错了什么?
在查看一些在线文档时,似乎特定的对象 ID 应该与路由一起传递。而不是这个:
{!! Form::model($fund, ['route' => 'funds.getQuery', 'method' => 'get'], $fund->id) !!}
你能试试下面的方法吗?
{!! Form::model($fund, ['route' => array('funds.getQuery', $fund->id), 'method' => 'get']) !!}
我需要在我的表单中使用 GET 来生成一个 url 查询字符串,但我还需要在我的路由中使用模型 ID。基本上,我想用表单提交生成的 url 查询字符串扩展 show($id) 方法。但它没有得到 id。 (POST 方法也没有得到它。)
这是我的:
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;
}]);
我的 show/{id} 方法运行良好。我做错了什么?
在查看一些在线文档时,似乎特定的对象 ID 应该与路由一起传递。而不是这个:
{!! Form::model($fund, ['route' => 'funds.getQuery', 'method' => 'get'], $fund->id) !!}
你能试试下面的方法吗?
{!! Form::model($fund, ['route' => array('funds.getQuery', $fund->id), 'method' => 'get']) !!}