i have morphmany relationship comments related question model know how newly inserted id when saving new comment model.
public function postcomment() { if(request::ajax() && auth::check()) { //input::merge(array_map('trim', input::all())); $comment = new comment; $comment->user_id = auth::user()->id; $comment->body = helper::strip_tags(input::get('body')); $question_id = input::get('question_id'); $question = question::find($question_id); // here in if statement how newly created id of comment if($question->comments()->save($comment)) { return response::json(array('success' => true, 'body' => input::get('body'), 'userlink' => html::linkroute('profile', auth::user()->username, array('id' => auth::user()->id)), 'date' => date("f j, y, g:i a") )); } else { return response::json(array('success' => false, 'body' => input::get('body'))); } } }
the saved comment record returned on save:
$comment = $question->comments()->save($comment); if($comment) { // comment saved $comment->id; } else { // comment not saved }
Comments
Post a Comment