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');
});