我是Laravel 4的新手,我得到这个错误:一些强制性参数缺失("id")以生成路由"cat_edit"的URL。
这是我的路线:
Route::get('/category/{id}/edit', array(
'as' => 'cat_edit',
'uses' => 'CategoryController@editAction'
))->where('id', '[0-9]+');
这是我的控制器:
public function editAction($id){
$category = Category::find($id);
$categories = Category::all();
return View::make('categories.edit', array(
'category' => $category ,
'categories' => $categories,
));
}
最后是我的视图:
@extends('layouts.main')
@section('title')
Edit category
@stop
@section('content')
<h1>Add a Category</h1>
{{ Form::open(array('action' => 'CategoryController@editAction')) }}
{{ Form::form_lab('text', 'name', 'Name') }}
{{ Form::form_lab('textarea', 'description', 'Description') }}
{{ Form::form_select('parent', 'Parent', $categories) }}
<div class="form-actions">
{{ Form::form_button('Validate') }}
</div>
{{ Form::close() }}
@stop
我已经找了好几个小时了,但我看不出我错在哪里。所有的,我的其他路线都很好。
谢谢!
您可以重写Form::open来使用URL::action。参见Laravel 4:将什么作为参数传递给Url类?如何将参数传递给URL::action。
的例子:
{{ Form::open(array('url' => URL::action('CategoryController@editAction', ['123']) )) }}