2014-08-29 70 views
0

我想要编辑的数据库条目,缺少参数1 PostController中:: postEditPost()

数据库是建立在这样一种方式,我可以做这取决于它们的版本帖子的回滚。

我第一次从数据库中检索条目:

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' =>  '[email protected]')); 
Route::post('/post/editpost/', array('as' => 'post-edit-post', 'uses' => '[email protected]')); 

创建一个新的进入数据库时​​,我怎样才能通过从getEditPost到postEditPost的ID?

回答

0

的一种方法是通过路径传递给它,这样你就可以得到它的方式,试图在你的控制器动作:

更改路线:

Route::post('/post/editpost/{id}', array('as' => 'post-edit-post', 'uses' => '[email protected]')); 

和你的形式开放:

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

谢谢@Antonio!这就是我正在寻找的!谢谢 :) – escGoat007 2014-08-30 20:01:43