【发布时间】:2019-02-02 02:43:00
【问题描述】:
我想获取每个月的数量总和,以便我可以在条形图上显示月份的数量
这是我的想法,但没有锻炼
$data1 = Borrow::groupBy(function($d) {
return Carbon::parse($d->created_at)->format('m')->sum('quantity');
})->get();
我的表结构
Schema::create('borrows', function (Blueprint $table) {
$table->increments('id');
$table->integer('member_id');
$table->integer('book_id');
$table->integer('quantity');
$table->integer('status')->default(0);
$table->timestamps();
});
【问题讨论】:
-
你的
quantity字段是字符串类型,你要求和,必须是整数类型? -
是的,它是整数类型,我复制了错误的故事结构
标签: php laravel eloquent laravel-5.6 laravel-collection