缺少PostController :: postEditPost()的参数1

时间:2014-08-29 17:22:33

标签: php laravel-4

我想对数据库条目进行编辑,

数据库的设置方式使我可以根据版本进行回滚。

我首先从数据库中检索条目:

public function getEditPost($id)
{   
    $posts = Post::find($id);
    return View::make('posts.edit')->with('posts', $posts); 
}

然后在表单中显示:

{{ Form::open(array('url' => '/post/editpost/' )) }}
{{ Form::label('content', 'Content') }}
{{ Form::textarea('content', Input::old('content', $posts->content_posts()->first()['content'])) }}
{{ Form::submit('Edit') }}
{{ Form::token() }}
{{ Form::close() }}

当我想从刚刚编辑过的内容中创建一个新条目时,我需要使用上一篇文章的ID来创建新条目:

public function postEditPost($id)
{
    $userId = Auth::user()->id;
    $posts = Post::find($id);
    $content = Input::get('content');

    $changePost = new ChangePost;
    $contentpost = ContentPost::find($posts);
    $changePost->user()->associate($userId);
    $changePost->content_post()->associate($postId);
    $contentpost->save();

    $postContent = new ContentPost;
    $postContent->content = $content;
    $postContent->post_id = $posts;
    $postContent->post_id = $post->id;
    $postContent->version = 1;
    $postContent->save();

}

以下是两条路线:

Route::get('/post/editpost/{id}', array('as' => 'post-edit', 'uses' =>       'PostController@getEditPost'));
Route::post('/post/editpost/', array('as' => 'post-edit-post', 'uses' => 'PostController@postEditPost'));

在数据库中创建新条目时,如何将ID从getEditPost传递到postEditPost?

1 个答案:

答案 0 :(得分:0)

一种方法是通过路由传递它,这样你就可以尝试进行控制器操作:

将您的路线更改为:

Route::post('/post/editpost/{id}', array('as' => 'post-edit-post', 'uses' => 'PostController@postEditPost'));

表格打开:

{{ Form::open(array('route' => array('post-edit-post', $posts->content_posts()->first()->id) )) }}