laravel 4中缺少路线错误

时间:2014-06-26 17:44:32

标签: php laravel routing crud

我通过制作简单的博客应用程序来学习laravel和练习。我没有更新文章。我的路线不见了,去了我的slug路线"在代码底部并抛出错误。 没有找到slug的错误,没关系。但为什么我的路线丢失了?我的其他路线工作创建,删除等。 我的错是什么? 注意:抱歉英语不好。

edit.blade.php

{{ Form::open(array('url'=>'update', 'method'=>'patch')) }} 
    <input type="hidden" name="id" value="{{ $article->id }}"> 
    <input type="text" name="title" placeholder="Title" value="{{ $article->title }}" />
    <textarea type="text" name="body" placeholder="Body">{{ $article->body }}</textarea>
    <input type="text" name="tags" placeholder="Tags" value="{{ $article->tags }}" />
    <input type="submit" value="Update" >
{{ Form::close() }}

routes.php文件

Route::post('update', array(
'uses' => 'HomeController@update'
))->before('auth');

Route::get('/{slug}', function($slug){
setlocale(LC_TIME, "tr,TR", "tr" , "turkish");
$article = Article::where('slug', $slug)->first();
$comments = $article->comments()->where('approve', '=', 1)->get();
$date = $article->created_at;   
$date = iconv('latin5','utf-8',strftime('%A %d %B %Y'));
return View::make('article', array(
    'article' => $article,
    'date' => $date,
    'comments' => $comments
));
});

和HomeController.php

public function update(){
    $rules = array(
        'title' => 'required|min:5|max:255',
        'body' => 'required|min:10',
        'tags' => 'required|min:5|max:100'
        );
    $validator = Validator::make(Input::all(), $rules);
    if ($validator->fails()) {
        return Redirect::back()->withErrors($validator);
    }
    $id = Input::get('id');
    $article = Article::find($id);
    $article->title = Input::get('title');
    $article->body = Input::get('body');
    $article->tags = Input::get('tags');
    $article->save();
    return Redirect::back()->with('message', 'Article was updated successfully.');
}

2 个答案:

答案 0 :(得分:0)

你已经完成了

'method'=>'patch'

但你的路线是

Route::post('update'...

将路线更改为此

Route::patch('update'...

答案 1 :(得分:0)

在您的表单中使用以下代码:

Form::open(array('action' => array('HomeController@update', $article->id), 'method' => 'put', ));