2014-08-29 76 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