我试图修改一个用于编辑和更新数据的表单。然而,当我尝试提交“编辑”表单时,我总是会得到一个'MethodNotAllowedHttpException‘。我不确定这是因为我使用的'PUT‘方法不正确,还是我的'EditAlbumsController.php’文件定义不正确。
edit-album.blade.php:
{{ Form::model($album, array('method' => 'PUT', 'route' => array('edit_album', $album->album_id))) }}
/* Form code here */
{{ Form::close() }}routes.php:
Route::get('gallery/album/{id}/edit', array('as'=>'edit_album', 'uses'=>'EditAlbumsController@update'));EditAlbumsController.php:
class EditAlbumsController extends AlbumsController {
public function __construct()
{
parent::__construct();
}
public function update($id)
{
$input = \Input::except('_method');
$validation = new Validators\Album($input);
if ($validation->passes())
{
$album = Album::find($id);
$album->album_name = $input['album_name'];
/* Additional database fields go here */
$album->touch();
return $album->save();
return \Redirect::route('gallery.album.show', array('id' => $id));
}
else
{
return \Redirect::route('gallery.album.edit', array('id' => $id))
->withInput()
->withErrors($validation->errors)
->with('message', \Lang::get('gallery::gallery.errors'));
}
} 任何帮助都是非常感谢的!
发布于 2014-10-23 14:40:41
您需要定义PUT路由(您不正确地使用GET)
Route::put('gallery/album/{id}/edit', array('as'=>'edit_album', 'uses'=>'EditAlbumsController@update'));https://stackoverflow.com/questions/26530688
复制相似问题