Laravel:如何将表单中的值传递给控制器​​?

Jos*_*osh 2 php laravel laravel-4

我有一个表格:

{ Form::open(array('action' => 'RatesController@postUserRate', $client->id)) }}
    {{ Form::text('rate', '', array('placeholder' => 'Enter new custom client rate...')) }}
    {{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
Run Code Online (Sandbox Code Playgroud)

如何通过表单将$ client-> id值传递给我的控制器方法?

我目前有一个控制器方法,如下所示:

public function postUserRate($id)
{
    $currentUser = User::find(Sentry::getUser()->id);
    $userRate = DB::table('users_rates')->where('user_id', $currentUser->id)->where('client_id', $id)->pluck('rate');

    if(is_null($userRate))
    {
    ...
    }else{
    ....
    }
}
Run Code Online (Sandbox Code Playgroud)

并且错误日志显示"对于RatesController :: postUserRate()缺少参数1"

关于如何将这个$ client-> id传递给我的控制器的任何想法,以便我可以按照我想要的那样使用它?

Jef*_*Way 17

添加{{ Form::hidden('id', $client->id) }}到表单.然后,当它被发布时,您可以按常规获取其值Input::get('id').

另外,删除postUserRate方法的参数.