我有 voyager 管理面板的 laravel 项目。现在我需要在我的管理仪表板上查看商店中产品的统计数据,但仅限于今天。所以它需要向我展示今天生产的所有产品,计算它并在我的仪表板上显示它。让我展示我的代码:这是我的DeltaDimmer.php:<?phpnamespace 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,我制作了一些产品只是为了测试。我做错了什么?
1 回答
aluckdog
TA贡献1847条经验 获得超7个赞
使用whereDate
而不是仅与比较where
$count = Storeone::whereDate('created_at', Carbon::today())->count();
- 1 回答
- 0 关注
- 67 浏览
添加回答
举报
0/150
提交
取消