A
A
Andr Lw12014-08-08 07:40:12
symfony
Andr Lw1, 2014-08-08 07:40:12

How to bind comments_table to posts_table in Laravel 4?

There are posts, and you need to tie the ability to add comments.
CommentController

$data = Input::all();
Comment::create($data);

In the controller I can get data from the form, but how to get the id of the current post, for further processing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andr Lw1, 2014-08-08
@lw1

Decision.
in routes.php :

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

in %filename%.blade.php :
{{ Form::model($post, array('action' => array('[email protected]', $post['id']))) }}
// Ваши данные
{{ Form::close() }}

in CommentController.php :
public function add($id){

      $data = Input::all();
      $new = $id;
      $data['post_id'] = $new;
      $comment = Comment::add($data);
}

and finally, in Comment.php :
$comment = Comment::create([

          //ваши данные
          //и id:
          'post_id' => $data['post_id']

        ]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question