Laravel表单打开了多个参数

时间:2014-11-28 12:34:49

标签: laravel laravel-4

我正在尝试使用以下代码传递表单打开的变量:

{{ Form::open(['method' => 'PATCH','route' => ['note.update','project','1','1']]) }}

这是我的NoteController.php文件

Class NoteController extends BaseController{
    public function update($belongs_to,$unique_id=0,$note_id=0){
        return $unique_id;
    }
}

routes.php文件是

Route::resource('note', 'NoteController'); 

为什么我只能访问$ belongs_to变量而$ unique_id和$ note_Id总是为0作为默认值?

1 个答案:

答案 0 :(得分:1)

这是因为在Route::resource注册的路线只占用一个网址参数。

看看this

所以你需要做的是使用这条路线:

Route::patch('note/{belongs_to}/{unique_id?}/{note_id?}', 'NoteController@update');

如果您想保留Route::resource之外的其他路线,只需在Route::resource之前添加

Route::patch('note/{belongs_to}/{unique_id?}/{note_id?}', 'NoteController@update');
Route::resource('note', 'NoteController');

如果您不想添加此类路线,则必须使用查询参数传递其他信息