繁体   English   中英

Laravel - voyager admin dimmer 统计

[英]Laravel - voyager admin dimmer statistic

我有带有航海者管理面板的 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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM