简体   繁体   中英

Laravel - voyager admin dimmer statistic

I have laravel project with voyager admin panel. Right now I need to see statistics on my admin dashboard for products in stores but only from today. So it needs to show me all products made today, to count it and show it on my dashboard.Let me show my code: Here is my 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'));
    }
}

So this is my DeltaDimmer.php . This line $count = Storeone::where('created_at', '=', Carbon::today())->count(); should count my products in Storeone only for today but right now it is showing me 0 and I made a few a products just for test. What I'm doing wrong?

使用whereDate而不是仅与where进行比较

$count = Storeone::whereDate('created_at', Carbon::today())->count();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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