Laravel 在我的路线中使用 View Composer 出现 htmlspecial 错误
Laravel using View Composer in my routes with htmlspecial error
我试图在我的路线中进行查询,以便视图编辑器加载所有记录并对其进行计数并将其显示在我的侧边栏中以供使用。
我认为查询没有问题,因为它在我的 shell 中使用 php artisan tinker 进行查询测试。
但是当我尝试在我的路线中执行此操作并将其传递给 menu.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();
})
]);
});
这是我的 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
如果有人能提供帮助,我们将不胜感激。
提前致谢。
那是因为您试图显示 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();
]);
我试图在我的路线中进行查询,以便视图编辑器加载所有记录并对其进行计数并将其显示在我的侧边栏中以供使用。
我认为查询没有问题,因为它在我的 shell 中使用 php artisan tinker 进行查询测试。
但是当我尝试在我的路线中执行此操作并将其传递给 menu.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();
})
]);
});
这是我的 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
如果有人能提供帮助,我们将不胜感激。 提前致谢。
那是因为您试图显示 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();
]);