我已经设置了laravel资源控制器并利用编辑和更新方法来编辑用户配置文件。我的个人资料表格太长了,所以我想把它分成两种形式。
问题是更新功能似乎内置在资源控制器中 - 我尝试只复制方法,添加输入并重命名。我更新了路线和视图,但收到了错误。我也尝试让两个表单调用相同的函数,但表单中包含的信息是从我的数据库中删除。
我的问题是,如何将表单拆分为两个,以便我可以从两个表单而不是一个表单更新我的用户配置文件?任何帮助,将不胜感激。谢谢
供参考,这是我的ContractorController
public function edit($id)
{
//
// get the contractor
$contractor = Contractor::find($id);
// show the edit form and pass the contractor
return View::make('contractors.edit')
->with('contractor', $contractor);
}
public function update($id)
{
//
// validate
// read more on validation at http://laravel.com/docs/validation
$rules = array(
);
$validator = Validator::make(Input::all(), $rules);
// process the login
if ($validator->fails()) {
return Redirect::to('contractors/' . $id . '/edit')
->withErrors($validator)
->withInput(Input::except('password'));
} else {
// store
$contractor = Contractor::find($id);
$contractor->name = Input::get('name');
$contractor->tag_line = Input::get('tag_line');
$contractor->contact_name = Input::get('contact_name');
//would like to split items below into a separate form:
$contractor->public_email = Input::get('public_email');
$contractor->phone = Input::get('phone');
$contractor->address_1 = Input::get('address_1');
$contractor->city = Input::get('city');
$contractor->state = Input::get('state');
$contractor->zip = Input::get('zip');
$contractor->website = Input::get('website');
$contractor->story = Input::get('story');
$contractor->save();
// redirect
Session::flash('message', 'Successfully updated profile!');
return Redirect::to('contractors');
}
}
edit.blade.php中的表单开始
{{ Form::model($contractor, array('route' => array('contractors.update', $contractor->id), 'class' => 'form-horizontal', 'method' => 'PUT')) }}