Php laravel 4.2更新结果不工作
routes.phpPhp laravel 4.2更新结果不工作,php,Php,routes.php Route::put('questions/{id}', array('as' => 'update.question','before' => 'csrf', 'uses'=> 'QuestionsController@update')); Route::get('question/{id}', array('as' => 'question', 'uses'=> 'QuestionsController@getview')); Route
Route::put('questions/{id}', array('as' => 'update.question','before' => 'csrf', 'uses'=> 'QuestionsController@update'));
Route::get('question/{id}', array('as' => 'question', 'uses'=> 'QuestionsController@getview'));
Route::get('questions/{id}/edit', array('as' => 'edit_question', 'uses'=> 'QuestionsController@edit'));
QuestionsController.php
public function edit($id)
{
if(!$this->question_belongs_to_user($id))
{
return Redirect::to('your_questions')
->with('message', 'Invalid Question');
}
return View::make('questions.edit')
->with('title', 'Make It Snappy Q&A - Home')
->with('question', Question::find($id));
}
public function update($id)
{
$id = Input::get('question_id');
if(!$this->question_belongs_to_user($id))
{
return Redirect::to('your_questions')
->with('message', 'Invalid Question');
}
$validation = Question::validate(Input::all());
if ($validation->passes()) {
$newData =[
'question' => Input::get('question'),
'solved' => Input::get('solved'),
];
$Question=Question::find($id);
$Question->fill($newData)->save();
return Redirect::to('question', $id)
->with('message', 'Your question has been updated!.');
} else {
return Redirect::to('edit_question')->withErrors($validation)->withInput();
}
}
edit.blade.php
@extends('layouts.default')
@“内容”一节
<h1>Edit Your Question</h1>
@if($errors->has())
<ul id="form-errors">
{{ $errors->first('question', '<li>:message</li>>') }}
{{ $errors->first('solved', '<li>:message</li>>') }}
</ul>
@endif
{{ Form::model($question, array('route' => array('update.question', $question->id), 'method' => 'put')) }}
<p>
{{ Form::label('question', 'Question') }}
{{ Form::text('question', $question->question) }}
</p>
<p>
{{ Form::label('solved', 'Solved') }}
@if($question->solved == 0 )
{{ Form::checkbox('solved', 1, false) }}
@elseif($question->solved == 1 )
{{ Form::checkbox('solved', 0, true) }}
@endif
</p>
{{ Form::hidden('question_id', $question->id) }}
<p> {{ Form::submit('Update') }} </p>
{{ Form::close() }}
其中记录更新到目标表中,但重定向到路由时
返回重定向::到'question',$id
在这里,它不起作用了
在尝试了两种方法后,Form::model和Form::open都失败了吗 重定向::到需要完整路径。将其更改为使用路由方法,并提供路由参数:
重定向::路由'question',数组'id'=>$id 请试着改写你的问题,让它更清楚。现在还不太清楚你的问题是什么。事实上,我的英语一般,不好,试着变得好$id,当我尝试使用dot时。在路由中不是分号,那么它的工作,但在其他部分仍然显示相同的错误
[2015-03-25 14:15:04] production.ERROR: exception 'Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException' in E:\Web\xampp\htdocs\makeitsnappy\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php:210