我试图在我的路线中进行查询,以便视图编辑器加载所有记录并对其进行计数并将其显示在我的侧边栏中。
我认为查询没有问题,因为它在我的 shell 中使用 php artisantinker 来测试查询的目的。
但是当我尝试在我的路线中执行此操作并将其传递给菜单.blade.php
这是我的路线中带有视图编辑器功能的代码。
// Menu View for Microbiologist
View::composer('microbiologist-dashboard.layouts.menu', function($view)
{
$view->with('counts', [
'microbiologist_task' => App\Models\AnalysisRequest::where('status', 'under_analyzation')
->whereHas('actors', function ($query) {
$microbiologist = Auth::guard('microbiologist')->user()->id;
$query->where('microbiologist_id', $microbiologist)->count();
})
]);
});
这是我的代码菜单.blade.php
<span class="pull-right-container">
@if($counts['microbiologist_task'])
<small class="label pull-right bg-yellow">{{ $counts['microbiologist_task'] }}</small>
@else
@endif
</span>
这是错误的屏幕截图。
我的项目关于UTF-8的配置有问题吗?或者我应该使用一些助手。谢谢顺便说一句我正在使用拉拉维尔 5.5
如果有人可以提供帮助,我们将不胜感激。
提前致谢。
那是因为你试图显示一个实例AnalysisRequest
而不是整数。使用正确的语法:
$view->with('counts', [
'microbiologist_task' => App\Models\AnalysisRequest::where('status', 'under_analyzation')
->whereHas('actors', function ($query) {
$microbiologist = Auth::guard('microbiologist')->user()->id;
$query->where('microbiologist_id', $microbiologist);
})
->count();
]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)