Laravel在我的路线中使用View Composer并出现htmlspecial错误 [英] Laravel using View Composer in my routes with htmlspecial error
问题描述
我正尝试在路线中查询,以便视图编辑器加载所有记录并对其进行计数,然后将其显示在我的侧边栏中以用于目的.
I was trying to do a query in my routes for the view composer to load all the records and count it and display it in my sidebar for purposes.
我认为查询没有问题,因为它在我的外壳中使用php artisan tinker进行了测试,以测试查询.
I think there is no problem with the query since it worked in my shell using the php artisan tinker for testing purposes of the query.
但是我在尝试将其传递给 menu.blade.php
But I got this error when I try to do it in my routes and pass it to the menu.blade.php
这是我的路线中带有View Composer函数的代码.
Here is the code in my routes with the view composer function.
// 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();
})
]);
});
这是我的 menu.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的配置是否有问题?还是应该使用一些帮手.谢谢顺便说一句,我正在使用 Laravel 5.5
is there something wrong with the config of my project about UTF-8? or should I use some helpers. Thanks btw I am using Laravel 5.5
感谢有人可以提供帮助. 预先感谢.
Appreciate if someone could help. Thanks in advance.
推荐答案
那是因为您试图显示AnalysisRequest
的实例而不是整数.使用正确的语法:
That's because you're trying to display an instance of AnalysisRequest
and not an integer. Use proper syntax:
$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();
]);
这篇关于Laravel在我的路线中使用View Composer并出现htmlspecial错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!