简体   繁体   English

laravel 4.2更新结果不起作用

[英]laravel 4.2 update result no working

routes.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::get('questions/{id}/edit', array('as' => 'edit_question', 'uses'=> 'QuestionsController@edit'));

QuestionsController.php 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 edit.blade.php

@extends('layouts.default')

@section('content') @section('内容')

<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() }}

@stop @停

try to update record following error facing, where is problem 尝试更新记录以下错误面对,哪里有问题

[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

where record is updated into the destination table but when redirect to the route return Redirect::to('question', $id) here it's not working 记录已更新到目标表中,但是当重定向到路由时return Redirect::to('question', $id)在这里它不起作用

after try both ways Form::model() , and Form::open() but in vain? 后尝试两种方式Form::model()Form::open()但徒劳吗?

Redirect::to() requires a full path. Redirect::to()需要完整路径。 Change it to use the route() method, and provide the route parameters: 它改为使用路由()方法,并提供路径参数:

Redirect::route('question', array('id' => $id));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM