首页 > 解决方案 > 如何防止页面刷新时数据库中的自动增量?拉拉维尔 7

问题描述

我有一些条件(如下所示)在数据库表('quizzes')的列('pass_number')中将值增加 1:

“测验”:

Schema::create('quizzes', function (Blueprint $table) {
        $table->id();

        $table->string('qname');

        $table->text('description');

        $table->text('subcategory');

        $table->text('by');

        $table->text('by_username');

        $table->text('profileUrl');
        
        $table->integer('minutes');

        $table->integer('cutoff');
        
        $table->integer('pass_number')->default(0)->nullable();

        $table->timestamps();
    });

健康)状况:

$cutoff1 = DB::table('quizzes')
                  ->where('id', '=', $quizId)
                  ->value('cutoff');

if ($percentage > $cutoff1) {

        DB::table('quizzes')
               ->where('id', $quizId)
               ->update([
                   'pass_number' => DB::raw('pass_number + 1')
               ]);
        
       }

我可以在“pass_number”中增加,但在页面刷新时我想停止它

*$percentage 我从用户在特定测验中的表现中获得。

标签: mysqllaravel

解决方案


推荐阅读