0
我想使用表单检索用户评论的数据,但我不太确定如何执行此操作,即使在查看在laravel文档和视频。如何从表单中检索数据(type =“text”)并将其存储在数据库中laravel 5.2
我 “CommentsController” 代码snipit看起来像这样
public function submitComment(Request $request){
$this->validate($request, [
'comment'=> 'required|max:500'
]);
$comment= new Comments;
$comment->comments=$request->input->('comment');
DB::table('comments')->insert(
array('user_id'=>1,
'post_id'=>1,
'comment'=> $comment)
);
,我的形式snipit看起来像这样
<?php
echo '<form method="POST" action="comments"> ';
echo '<input name="comment" type="text" cols="40" rows="5" style="width:200px; height:50px;" placeholder="Type Here">';
echo '<input type="submit">' ;
echo '</form>';
?>
和我的数据库中的表看起来像这样
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('post_id')->unsigned();
$table->string('comments');
$table->timestamps();
//Foreign Keys
$table->foreign('post_id')
->references('id')->on('posts')
->onDelete('cascade');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
});