我不确定如何在控制器中增加整数
这就是我尝试过的。我正在抓取代码,添加一个然后保存。这将产生错误:“在字符串上调用成员函数save()”
我将返回计数以在浏览器中查看结果。在Tinker中运行$ count = Count :: find(1)-> count可以得出正确的金额。
public function update(Request $request, Count $count)
{
$count = Count::find(1)->count;
$addOne = $count + 1;
$count->save();
return ($count);
}
有人可以告诉我这是怎么不起作用的,我该怎么做才能解决?
这是迁移:
public function up()
{
Schema::create('counts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('count');
$table->timestamps();
});
}
这是模态:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Count extends Model
{
protected $fillable = [
'count'
];
}
慕斯709654
哔哔one
ITMISS