php - Laravel - 航海者管理调光器统计
问题描述
我有 voyager 管理面板的 laravel 项目。现在我需要在我的管理仪表板上查看商店中产品的统计数据,但仅限于今天。所以它需要向我展示今天生产的所有产品,计算它并在我的仪表板上显示它。让我展示我的代码:这是我的DeltaDimmer.php
:
<?php
namespace TCG\Voyager\Widgets;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use TCG\Voyager\Facades\Voyager;
use Carbon\Carbon;
use App\Storeone;
class DeltaDimmer extends BaseDimmer
{
/**
* The configuration array.
*
* @var array
*/
protected $config = [];
/**
* Treat this method as a controller action.
* Return view() or other content to display.
*/
public function run()
{
$count = Storeone::where('created_at', '=', Carbon::today())->count();
//$count = \App\Storeone::where('created_at', '=', Carbon::today())->count();
$string = 'Rad: ';
return view('voyager::dimmer', array_merge($this->config, [
'icon' => 'voyager-eye',
'title' => "{$string} {$count}",
'text' => 'Optika Podgorica/Delta',
'button' => [
'text' => 'Prikazi',
'link' => route('voyager.optikadelta.index'),
],
'image' => voyager_asset('images/widget-backgrounds/04.jpeg'),
]));
}
/**
* Determine if the widget should be displayed.
*
* @return bool
*/
public function shouldBeDisplayed()
{
return Auth::user()->can('browse', Voyager::model('Post'));
}
}
所以这是我的DeltaDimmer.php
。这条线$count = Storeone::where('created_at', '=', Carbon::today())->count();
应该Storeone
只计算我今天的产品,但现在它显示为 0,我制作了一些产品只是为了测试。我做错了什么?
解决方案
使用whereDate
而不是仅与比较where
$count = Storeone::whereDate('created_at', Carbon::today())->count();
推荐阅读
- date - 谷歌表格查询两个日期之间的总和
- google-bigquery - 用于查询结果的 BigQuery API 问题
- c++ - 将 'const franka::Robot' 作为 'this' 参数传递会丢弃限定符 [-fpermissive] robot.loadModel();
- python - 如何在python中断言多行正则表达式
- jquery - 使用jQuery将特定th下的单元格值转换为链接
- java - Jackson 映射器跳过类名(反序列化问题)
- c# - 如何使用 EF Core 正确更新行?
- r - 在 R 中的 ggplot 中对具有相同列名的数据框进行子集和绘图
- python - 如何在 plotly 中创建一个包含 6 行子图的图?
- php - 从 URL 中删除 ?fbclid 查询字符串