所以我试图检查我在“发送”行中的值是真还是假然后我想创建一个触发器,它根据该行中的值更改 html 值。
我尝试创建一个带有 2 个变量的触发器,然后我使用 if 语句在数据库和真/假之间进行比较。
数据库迁移
public function up()
{
Schema::create('QrCode', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('codes',255);
$table->timestamp('created_at');
$table->boolean("sent")->default(0);
$table->timestamp("sent_at")->nullable();
$table->boolean("used")->default(0);
$table->timestamp("used_at")->nullable();
});
}
控制器.php
public function update($id)
{
$sent = DB::table('qrcode')->where('id', $id)->get(['sent']);
if ($sent == false) {
DB::table('qrcode')->where('id', $id)->update(array('sent' => 1, 'sent_at' => now()));
}
if ($sent == true){
DB::table('qrcode')->where('id', $id)->update(array('sent' => 0, 'sent_at' => now()));
}
return back();
}
Blade.php(我认为没有必要,但我会把它放在这里)
<td>
@if($qrcode->used === 1)
<b><p name="Yes">Yes</p></b>
@else
<b><p>No</p></b>
@endif
</td>
路由和模型创建得很好……我的问题出在控制器上!
每次我尝试更改值时,即使数据库行为假,代码也始终返回 1。
MMMHUHU