Laravel 5:使用模型绑定的GET方法时无法获取id

时间:2015-10-06 18:32:35

标签: php forms laravel routing laravel-5

我需要在表单中使用GET才能生成url查询字符串,但我还需要在我的路由中使用模型ID。基本上,我想使用表单提交生成的url查询字符串扩展show($ 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}方法运行正常。我做错了什么?

1 个答案:

答案 0 :(得分:0)

在查看一些在线文档时,似乎应该将特定对象ID与路径一起传递。而不是:

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

您可以尝试以下方法吗?

{!! Form :: model($ fund,[' route' => array(' funds.getQuery',$ fund-> id),'方法' = >'得到'])!!}