如何在laravel 5.2中获取表单的动作路径

时间:2016-11-16 19:34:57

标签: php laravel-5

我已使用此表单更新我的数据

<form class="form-vertical" role="form" method="post" action="">
            <div class="form-group{{ $errors->has('comments') ? ' has-error' : '' }}">
                <input type="text" name="comments" class="form-control" id="comments" value="{!! $comment->comments ?: '' !!}">
                @if ($errors->has('comments'))
                    <span class="help-block">{{ $errors->first('comments') }}</span>
                @endif
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-info">Update Commment</button>
            </div>
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
            {!! method_field('PUT') !!}
        </form>

此表格路线是

Route::put('projects/{projects}/collaborators/{id}',['uses'=>'ProjectCollaboratorsController@update',]);

我需要如何进行表单操作

<form class="form-vertical" role="form" method="post" action="">

2 个答案:

答案 0 :(得分:0)

您可以将路线定义为:

Route::put('projects/{projects}/collaborators/{id}',['uses'=>'ProjectCollaboratorsController@update', 'as' => 'projects.collaborators.update']);

然后在您的表单中,您可以这样做:

<form class="form-vertical" role="form" method="post" action="{{ route('projects.collaborators.update', ['projects' => 1, 'collaborators' => 2]) }}">

Docs

答案 1 :(得分:0)

另一种选择是使用Laravel Collective

然后,您可以创建与echo Form::open(['action' => 'Controller@method'])

一样简单的表单