Php 调用未定义的方法Illumb\Database\Query\Builder::insertans()

Php 调用未定义的方法Illumb\Database\Query\Builder::insertans(),php,laravel,Php,Laravel,我在mysql数据库中插入数据时遇到了一个laravel问题 这是我在web.php中的控制器: Route::post('/insertans', 'Controller@insertans'); 这是我的mysql php函数代码: function insertans(Request $req) { $question1 = $req->input('question1'); $question2 = $req->input('question

我在mysql数据库中插入数据时遇到了一个laravel问题

这是我在web.php中的控制器:

Route::post('/insertans', 'Controller@insertans');
这是我的mysql php函数代码:

function insertans(Request $req) {
        $question1 = $req->input('question1');
        $question2 = $req->input('question2');
        $question3 = $req->input('question3');

        $ans = array("question1"=>$question1,"question2"=>$question2,"question3"=>$question3);

        DB::table('jawaban')->insertans($ans);

        echo "Data successfully added";
    }
这是我的html,用于视觉目的

<!DOCTYPE html>
<html>
<head>
    <title>PACKET A</title>
</head>
<body>
<form action="/insertans" method="post">
        <table>
            <tr>
            {{ csrf_field() }}
                <td>1. &emsp; What does HTTP stands for?  </td>
                &emsp;<td><input type="text" name="question1"></td>
            </tr>

            <tr>

                <td>2. &emsp; What does JS stands for?  </td>
                &emsp;<td><input type="text" name="question2"></td>
            </tr>

            <tr>

                <td>3. &emsp; What does CSS stands for?  </td>
                &emsp;<td><input type="text" name="question3"></td>
            </tr>


            <tr>
                <td><input type="submit" name="submit" value="Submit"></td>
                <td><input type="reset" name="cls" value="Cancel"></td>
            </tr>

        </table>
    </form>

</body>
</html>

包A
{{csrf_field()}}
1. &emsp;HTTP代表什么?
&emsp;
2. &emsp;JS代表什么?
&emsp;
3. &emsp;CSS代表什么?
&emsp;

查询生成器上没有
insertans()
方法,因此会出现错误


您可能打算执行
DB::table('jawaban')->insert($ans)而不是
DB::table('jawaban')->insertans($ans)

查询生成器上没有
insertans()
方法,这就是为什么会出现错误

您可能打算执行
DB::table('jawaban')->insert($ans)而不是
DB::table('jawaban')->insertans($ans)

使用
insert()

insertans()
是一种控制器方法,在生成查询时不应使用它。

使用
insert()


insertans()
是一种控制器方法,在生成查询时不应使用它。

您遇到了什么错误?请尽可能详细地说明问题。您遇到了什么错误?请尽可能详细地说明问题。
DB::table('jawaban')->insert($ans);